D:/Storage/CVS_Head/h323plus/include/codecs.h

00001 /*
00002  * codecs.h
00003  *
00004  * H.323 protocol handler
00005  *
00006  * Open H323 Library
00007  *
00008  * Copyright (c) 1998-2000 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open H323 Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions of this code were written with the assisance of funding from
00025  * Vovida Networks, Inc. http://www.vovida.com.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Log: codecs.h,v $
00030  * Revision 1.2  2007/10/19 19:53:44  shorne
00031  * ported latest Video updates in OpenH323 committed after h323plus initial fork thanks
00032  *  Robert
00033  *
00034  * Revision 1.1  2007/08/06 20:50:48  shorne
00035  * First commit of h323plus
00036  *
00037  * Revision 1.81.2.5  2007/07/19 20:10:27  shorne
00038  * Changed HAS_AEC to H323_AEC
00039  *
00040  * Revision 1.81.2.4  2007/02/10 23:56:40  shorne
00041  * Added comment
00042  *
00043  * Revision 1.81.2.3  2007/02/05 05:17:00  shorne
00044  * Added ability to send general codec options to Video Plugins
00045  *
00046  * Revision 1.81.2.2  2007/01/30 14:39:55  shorne
00047  * Corrections and Improvements patch supplied by Guilhem Tardy
00048  *
00049  * Revision 1.81.2.1  2006/12/23 19:08:02  shorne
00050  * Plugin video codecs & sundry
00051  *
00052  * Revision 1.81  2006/08/01 06:17:48  csoutheren
00053  * Fix bit rate control units
00054  * Add access function on code for max bit rate
00055  * Thanks to Paolo Amadini
00056  *
00057  * Revision 1.80  2006/05/16 11:28:58  shorne
00058  * added AEC support and  more call hold support.
00059  *
00060  * Revision 1.79  2006/01/26 03:31:08  shorne
00061  * Add the ability to remove a local input device when placing a call on hold
00062  *
00063  * Revision 1.78  2005/11/30 13:05:01  csoutheren
00064  * Changed tags for Doxygen
00065  *
00066  * Revision 1.77  2005/06/07 07:09:13  csoutheren
00067  * Removed compiler warnings on Windows
00068  *
00069  * Revision 1.76  2005/06/07 03:22:22  csoutheren
00070  * Added patch 1198741 with support for plugin codecs with generic capabilities
00071  * Added patch 1198754 with support for setting quality level on audio codecs
00072  * Added patch 1198760 with GSM-AMR codec support
00073  * Many thanks to Richard van der Hoff for his work
00074  *
00075  * Revision 1.75  2005/01/03 06:25:52  csoutheren
00076  * Added extensive support for disabling code modules at compile time
00077  *
00078  * Revision 1.74  2004/07/03 06:48:26  rjongbloed
00079  * Split video temporal/spatial trade off H.245 packets to separate command and
00080  *   indication functions and added quality parameter, thanks Guilhem Tardy.
00081  *
00082  * Revision 1.73  2004/05/09 10:08:34  csoutheren
00083  * Changed new DecodeFrame to return bytes decoded rather than samples decoded
00084  * Added support for new DecodeFrame to plugin manager
00085  *
00086  * Revision 1.72  2004/05/02 04:52:23  rjongbloed
00087  * Fixed problems with G.711 caused by fixing problem with G.723.1-5k3 mode.
00088  *
00089  * Revision 1.71  2004/03/24 00:39:12  dereksmithies
00090  * Changes from Michael Smith for use in reporting frames/second. Many Thanks
00091  *
00092  * Revision 1.70  2003/12/14 10:42:29  rjongbloed
00093  * Changes for compilability without video support.
00094  *
00095  * Revision 1.69  2003/11/12 11:14:21  csoutheren
00096  * Added H323FramedAudioCodec::DecodeSilenceFrame thanks to Henry Harrison of AliceStreet
00097  *
00098  * Revision 1.68  2003/07/16 10:43:12  csoutheren
00099  * Added SwapChannel function to H323Codec to allow media hold channels
00100  * to work better. Thanks to Federico Pinna
00101  *
00102  * Revision 1.67  2003/05/27 09:39:15  dereksmithies
00103  * Add frames per sec variable to the videocodec class
00104  *
00105  * Revision 1.66  2002/12/16 09:11:15  robertj
00106  * Added new video bit rate control, thanks Walter H. Whitlock
00107  *
00108  * Revision 1.65  2002/09/16 01:14:15  robertj
00109  * Added #define so can select if #pragma interface/implementation is used on
00110  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00111  *
00112  * Revision 1.64  2002/08/05 10:03:47  robertj
00113  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00114  *
00115  * Revision 1.63  2002/01/23 06:13:52  robertj
00116  * Added filter function hooks to codec raw data channel.
00117  *
00118  * Revision 1.62  2002/01/23 01:58:25  robertj
00119  * Added function to determine if codecs raw data channel is native format.
00120  *
00121  * Revision 1.61  2002/01/22 16:17:19  rogerh
00122  * Back out the DTMF Decoder class. There will soon be a better way
00123  * to do this.
00124  *
00125  * Revision 1.60  2002/01/22 16:09:38  rogerh
00126  * Back out the DTMF detection from H323FramedAudioCodec::Write().
00127  * There will shortly be a better place for it.
00128  *
00129  * Revision 1.59  2002/01/22 15:21:47  rogerh
00130  * Add DTMF decoding to PCM audio streams. This has been tested with
00131  * NetMeeting sending Dial Pad codes, using the G.711 codec.
00132  * At this time, DTMF codes (fron NetMeeting) are just displayed on the
00133  * screen and are not passed up to the users application.
00134  *
00135  * Revision 1.58  2002/01/13 23:56:01  robertj
00136  * Added mutex so can change raw data channel while reading/writing from codec.
00137  *
00138  * Revision 1.57  2001/12/04 05:13:09  robertj
00139  * Added videa bandwidth limiting code for H.261, thanks Jose Luis Urien.
00140  *
00141  * Revision 1.56  2001/11/16 01:05:21  craigs
00142  * Changed to allow access to uLaw/ALaw to/from linear functions
00143  *
00144  * Revision 1.55  2001/10/23 02:18:06  dereks
00145  * Initial release of CU30 video codec.
00146  *
00147  * Revision 1.54  2001/09/25 03:14:47  dereks
00148  * Add constant bitrate control for the h261 video codec.
00149  * Thanks Tiziano Morganti for the code to set bit rate. Good work!
00150  *
00151  * Revision 1.53  2001/09/11 01:24:36  robertj
00152  * Added conditional compilation to remove video and/or audio codecs.
00153  *
00154  * Revision 1.52  2001/08/28 09:27:38  robertj
00155  * Updated documentation to reflect some relationships between functions.
00156  *
00157  * Revision 1.51  2001/03/29 23:44:35  robertj
00158  * Added ability to get current silence detect state and threshold.
00159  * Changed silence detection to use G.723.1 SID frames as indicator of
00160  *   silence instead of using the average energy and adaptive threshold.
00161  * Changed default signal on deadband time to be much shorter.
00162  *
00163  * Revision 1.50  2001/02/09 05:16:24  robertj
00164  * Added #pragma interface for GNU C++.
00165  *
00166  * Revision 1.49  2001/01/25 07:27:14  robertj
00167  * Major changes to add more flexible OpalMediaFormat class to normalise
00168  *   all information about media types, especially codecs.
00169  *
00170  * Revision 1.48  2000/12/19 22:33:44  dereks
00171  * Adjust so that the video channel is used for reading/writing raw video
00172  * data, which better modularizes the video codec.
00173  *
00174  * Revision 1.47  2000/10/13 01:47:26  dereks
00175  * Include command option for setting the number of transmitted video
00176  * frames per second.   use --videotxfps n
00177  *
00178  * Revision 1.46  2000/09/08 06:41:37  craigs
00179  * Added ability to set video device
00180  * Added ability to select test input frames
00181  *
00182  * Revision 1.45  2000/08/31 08:15:32  robertj
00183  * Added support for dynamic RTP payload types in H.245 OpenLogicalChannel negotiations.
00184  *
00185  * Revision 1.44  2000/08/21 04:45:06  dereks
00186  * Fix dangling pointer that caused segfaults for windows&unix users.
00187  * Improved the test image which is used when video grabber won't open.
00188  * Added code to handle setting of video Tx Quality.
00189  * Added code to set the number of background blocks sent with every frame.
00190  *
00191  * Revision 1.43  2000/05/16 02:04:16  craigs
00192  * Added access functions for silence compression mode
00193  *
00194  * Revision 1.42  2000/05/02 04:32:24  robertj
00195  * Fixed copyright notice comment.
00196  *
00197  * Revision 1.41  2000/04/14 20:11:16  robertj
00198  * Removed redundent member variable from H323FramedAudioCodec.
00199  *
00200  * Revision 1.40  2000/03/30 23:10:50  robertj
00201  * Fixed error in comments regarding GetFramerate() function.
00202  *
00203  * Revision 1.39  2000/03/21 03:06:47  robertj
00204  * Changes to make RTP TX of exact numbers of frames in some codecs.
00205  *
00206  * Revision 1.38  2000/02/28 13:00:22  robertj
00207  * Added some virtual keywords at the request of Yura Ershov
00208  *
00209  * Revision 1.37  2000/02/10 03:08:02  craigs
00210  * Added ability to specify NTSC or PAL video format
00211  *
00212  * Revision 1.36  2000/02/04 05:00:08  craigs
00213  * Changes for video transmission
00214  *
00215  * Revision 1.35  2000/01/13 04:03:45  robertj
00216  * Added video transmission
00217  *
00218  * Revision 1.34  1999/12/31 00:05:36  robertj
00219  * Added Microsoft ACM G.723.1 codec capability.
00220  *
00221  * Revision 1.33  1999/12/29 01:19:16  craigs
00222  * Fixed problem with RTP payload type variable
00223  *
00224  * Revision 1.32  1999/12/23 23:02:34  robertj
00225  * File reorganision for separating RTP from H.323 and creation of LID for VPB support.
00226  *
00227  * Revision 1.31  1999/11/29 09:01:46  craigs
00228  * Added new code for new video code interface
00229  *
00230  * Revision 1.30  1999/11/29 04:50:11  robertj
00231  * Added adaptive threshold calculation to silence detection.
00232  *
00233  * Revision 1.29  1999/11/20 00:53:46  robertj
00234  * Fixed ability to have variable sized frames in single RTP packet under G.723.1
00235  *
00236  * Revision 1.28  1999/11/13 14:10:32  robertj
00237  * Changes to make silence detection selectable.
00238  *
00239  * Revision 1.27  1999/11/11 23:28:52  robertj
00240  * Added first cut silence detection algorithm.
00241  *
00242  * Revision 1.26  1999/11/04 00:43:42  robertj
00243  * Added extra constructors for nonStandard codecs.
00244  *
00245  * Revision 1.25  1999/10/14 12:03:08  robertj
00246  * Fixed comment.
00247  *
00248  * Revision 1.24  1999/10/08 09:59:01  robertj
00249  * Rewrite of capability for sending multiple audio frames
00250  *
00251  * Revision 1.23  1999/10/08 04:58:37  robertj
00252  * Added capability for sending multiple audio frames in single RTP packet
00253  *
00254  * Revision 1.22  1999/09/23 07:25:12  robertj
00255  * Added open audio and video function to connection and started multi-frame codec send functionality.
00256  *
00257  * Revision 1.21  1999/09/21 14:51:33  robertj
00258  * Fixed NonStandardCapabilityInfo class virtual destructor (and name).
00259  *
00260  * Revision 1.20  1999/09/21 14:04:41  robertj
00261  * Added non-standard codec capability classes
00262  *
00263  * Revision 1.19  1999/09/21 08:12:49  craigs
00264  * Added support for video codecs and H261
00265  *
00266  * Revision 1.18  1999/09/18 13:27:24  craigs
00267  * Added ability disable jitter buffer for codecs
00268  * Added ability to access entire RTP frame from codec Write
00269  *
00270  * Revision 1.17  1999/09/08 04:05:48  robertj
00271  * Added support for video capabilities & codec, still needs the actual codec itself!
00272  *
00273  * Revision 1.16  1999/08/31 12:34:18  robertj
00274  * Added gatekeeper support.
00275  *
00276  * Revision 1.15  1999/08/25 03:08:23  robertj
00277  * Added UserInput capability.
00278  * Allowed the attachment of a channel on a codec to optionally delete the channel object,
00279  *
00280  * Revision 1.14  1999/07/22 14:32:48  robertj
00281  * Fixed erroneous comments
00282  *
00283  * Revision 1.13  1999/07/16 16:05:48  robertj
00284  * Added "human readable" codec type name display.
00285  *
00286  * Revision 1.12  1999/07/15 14:45:35  robertj
00287  * Added propagation of codec open error to shut down logical channel.
00288  * Fixed control channel start up bug introduced with tunnelling.
00289  *
00290  * Revision 1.11  1999/07/13 09:53:24  robertj
00291  * Fixed some problems with jitter buffer and added more debugging.
00292  *
00293  * Revision 1.10  1999/07/09 06:09:49  robertj
00294  * Major implementation. An ENORMOUS amount of stuff added everywhere.
00295  *
00296  * Revision 1.9  1999/06/24 13:32:45  robertj
00297  * Fixed ability to change sound device on codec and fixed NM3 G.711 compatibility
00298  *
00299  * Revision 1.8  1999/06/22 13:49:40  robertj
00300  * Added GSM support and further RTP protocol enhancements.
00301  *
00302  * Revision 1.7  1999/06/14 15:08:40  robertj
00303  * Added GSM codec class frame work (still no actual codec).
00304  *
00305  * Revision 1.6  1999/06/14 06:39:08  robertj
00306  * Fixed problem with getting transmit flag to channel from PDU negotiator
00307  *
00308  * Revision 1.5  1999/06/14 05:15:55  robertj
00309  * Changes for using RTP sessions correctly in H323 Logical Channel context
00310  *
00311  * Revision 1.4  1999/06/13 12:41:14  robertj
00312  * Implement logical channel transmitter.
00313  * Fixed H245 connect on receiving call.
00314  *
00315  * Revision 1.3  1999/06/09 05:26:19  robertj
00316  * Major restructuring of classes.
00317  *
00318  * Revision 1.2  1999/06/06 06:06:36  robertj
00319  * Changes for new ASN compiler and v2 protocol ASN files.
00320  *
00321  * Revision 1.1  1999/01/16 01:31:01  robertj
00322  * Initial revision
00323  *
00324  */
00325 
00326 #ifndef __CODECS_H
00327 #define __CODECS_H
00328 
00329 #ifdef P_USE_PRAGMA
00330 #pragma interface
00331 #endif
00332 
00333 
00334 #include <mediafmt.h>
00335 #include <rtp.h>
00336 #include <channels.h>
00337 #include "openh323buildopts.h"
00338 
00339 
00340 /* The following classes have forward references to avoid including the VERY
00341    large header files for H225 and H245. If an application requires access
00342    to the protocol classes they can include them, but for simple usage their
00343    inclusion can be avoided.
00344  */
00345 class H245_MiscellaneousCommand_type;
00346 class H245_MiscellaneousIndication_type;
00347 class H323Connection;
00348 
00349 
00350 
00352 
00360 class PAec;
00361 class H323Codec : public PObject
00362 {
00363   PCLASSINFO(H323Codec, PObject);
00364 
00365   public:
00366     enum Direction {
00367       Encoder,
00368       Decoder
00369     };
00370 
00371     H323Codec(
00372       const OpalMediaFormat & mediaFormat, 
00373       Direction direction       
00374     );
00375 
00376 
00389     virtual BOOL Open(
00390       H323Connection & connection 
00391     );
00392 
00395     virtual void Close() = 0;
00396 
00414     virtual BOOL Read(
00415       BYTE * buffer,            
00416       unsigned & length,        
00417       RTP_DataFrame & rtpFrame  
00418     ) = 0;
00419 
00431     virtual BOOL Write(
00432       const BYTE * buffer,          
00433       unsigned length,              
00434       const RTP_DataFrame & frame,  
00435       unsigned & written            
00436     ) = 0;
00437 
00440     virtual unsigned GetFrameRate() const;
00441 
00445     virtual void OnFlowControl(
00446       long bitRateRestriction   
00447     );
00448 
00452     virtual void OnMiscellaneousCommand(
00453       const H245_MiscellaneousCommand_type & type  
00454     );
00455 
00459     virtual void OnMiscellaneousIndication(
00460       const H245_MiscellaneousIndication_type & type  
00461     );
00462 
00463     Direction GetDirection()   const { return direction; }
00464 
00465     virtual const OpalMediaFormat & GetMediaFormat() const { return mediaFormat; }
00466     OpalMediaFormat & GetWritableMediaFormat() { return mediaFormat; }
00467 
00468     virtual BOOL SetFrameSize(int /*frameWidth*/, int /*frameHeight*/) { return FALSE; };
00469 
00477     virtual BOOL AttachChannel(
00478       PChannel * channel,     
00479       BOOL autoDelete = TRUE  
00480     );
00481 
00486     virtual PChannel * SwapChannel(
00487       PChannel * newChannel,  
00488       BOOL autoDelete = TRUE  
00489     );
00490 
00493     virtual BOOL CloseRawDataChannel();
00494 
00498     PChannel *GetRawDataChannel()
00499       { return rawDataChannel; }
00500 
00507     virtual BOOL IsRawDataChannelNative() const;
00508 
00511     BOOL ReadRaw(
00512       void * data,
00513       PINDEX size,
00514       PINDEX & length
00515     );
00516 
00519     BOOL WriteRaw(
00520       void * data,
00521       PINDEX length
00522     );
00523 
00530     BOOL AttachLogicalChannel(H323Channel *channel);
00531 
00532     class FilterInfo : public PObject {
00533         PCLASSINFO(FilterInfo, PObject);
00534       public:
00535         FilterInfo(H323Codec & c, void * b, PINDEX s, PINDEX l)
00536           : codec(c), buffer(b), bufferSize(s), bufferLength(l) { }
00537 
00538         H323Codec & codec;
00539         void      * buffer;
00540         PINDEX      bufferSize;
00541         PINDEX      bufferLength;
00542     };
00543 
00565     void AddFilter(
00566       const PNotifier & notifier
00567     );
00568 
00572     virtual BOOL SetRawDataHeld(BOOL hold );
00573 
00574   protected:
00575     Direction direction;
00576     OpalMediaFormat mediaFormat;
00577     
00578     H323Channel * logicalChannel; // sends messages from receive codec to tx codec.
00579 
00580     PChannel * rawDataChannel;  // connection to the hardware for reading/writing data.
00581     BOOL       deleteChannel;
00582     PMutex     rawChannelMutex;
00583 
00584     PINDEX     lastSequenceNumber;  // Detects lost RTP packets in the video codec.
00585 
00586     PLIST(FilterList, PNotifier);
00587     FilterList filters;
00588 };
00589 
00590 #ifndef NO_H323_AUDIO_CODECS
00591 
00592 
00599 class PAec;
00600 class H323AudioCodec : public H323Codec
00601 {
00602   PCLASSINFO(H323AudioCodec, H323Codec);
00603 
00604   public:
00610     H323AudioCodec(
00611       const OpalMediaFormat & mediaFormat, 
00612       Direction direction       
00613     );
00614 
00615     ~H323AudioCodec();
00616 
00625     virtual BOOL Open(
00626       H323Connection & connection 
00627     );
00628 
00636     virtual void Close();
00637 
00640     virtual unsigned GetFrameRate() const;
00641 
00642     enum SilenceDetectionMode {
00643       NoSilenceDetection,
00644       FixedSilenceDetection,
00645       AdaptiveSilenceDetection
00646     };
00647 
00651     void SetSilenceDetectionMode(
00652       SilenceDetectionMode mode,   
00653       unsigned threshold = 0,      
00654       unsigned signalDeadband = 80,    
00655       unsigned silenceDeadband = 3200, 
00656       unsigned adaptivePeriod = 4800   
00657     );
00658 
00667     SilenceDetectionMode GetSilenceDetectionMode(
00668       BOOL * isInTalkBurst = NULL,        
00669       unsigned * currentThreshold = NULL  
00670     ) const;
00671 
00672     
00679     virtual void SetTxQualityLevel(int /*qlevel*/) {}
00680 
00684     virtual int GetTxQualityLevel(int /*qlevel*/) { return 1; }
00685     
00692     virtual BOOL DetectSilence();
00693 
00701     virtual unsigned GetAverageSignalLevel();
00702 
00706     virtual BOOL SetRawDataHeld(BOOL hold);
00707 
00708 #ifdef H323_AEC 
00709 
00711         virtual void AttachAEC(
00712        PAec * /*_ARC*/   
00713     ) {};
00714 #endif
00715 
00716   protected:
00717     unsigned samplesPerFrame;
00718 
00719     SilenceDetectionMode silenceDetectMode;
00720 
00721     unsigned signalDeadbandFrames;  // Frames of signal before talk burst starts
00722     unsigned silenceDeadbandFrames; // Frames of silence before talk burst ends
00723     unsigned adaptiveThresholdFrames; // Frames to min/max over for adaptive threshold
00724 
00725     BOOL     inTalkBurst;           // Currently sending RTP data
00726     unsigned framesReceived;        // Signal/Silence frames received so far.
00727     unsigned levelThreshold;        // Threshold level for silence/signal
00728     unsigned signalMinimum;         // Minimum of frames above threshold
00729     unsigned silenceMaximum;        // Maximum of frames below threshold
00730     unsigned signalFramesReceived;  // Frames of signal received
00731     unsigned silenceFramesReceived; // Frames of silence received
00732     BOOL         IsRawDataHeld;
00733 };
00734 
00735 
00744 class PAec;
00745 class H323FramedAudioCodec : public H323AudioCodec
00746 {
00747   PCLASSINFO(H323FramedAudioCodec, H323AudioCodec);
00748 
00749   public:
00755     H323FramedAudioCodec(
00756       const OpalMediaFormat & mediaFormat, 
00757       Direction direction       
00758     );
00759 
00777     virtual BOOL Read(
00778       BYTE * buffer,            
00779       unsigned & length,        
00780       RTP_DataFrame & rtpFrame  
00781     );
00782 
00795     virtual BOOL Write(
00796       const BYTE * buffer,            
00797       unsigned length,                
00798       const RTP_DataFrame & rtpFrame, 
00799       unsigned & written              
00800     );
00801 
00802 
00807     virtual unsigned GetAverageSignalLevel();
00808 
00809 
00815     virtual BOOL EncodeFrame(
00816       BYTE * buffer,    
00817       unsigned & length 
00818     ) = 0;
00819 
00824     virtual BOOL DecodeFrame(
00825       const BYTE * buffer,   
00826       unsigned length,       
00827       unsigned & written,    
00828       unsigned & bytesOutput 
00829     );
00830     virtual BOOL DecodeFrame(
00831       const BYTE * buffer,  
00832       unsigned length,      
00833       unsigned & written    
00834     );
00835 
00840     virtual void DecodeSilenceFrame(
00841       void * buffer,  
00842       unsigned length       
00843     )
00844     { memset(buffer, 0, length); }
00845 
00846 #ifdef H323_AEC 
00847 
00849         virtual void AttachAEC(
00850        PAec * _ARC   
00851     );
00852 #endif
00853 
00854   protected:
00855         PAec * aec;     // Acoustic Echo Canceller
00856     PShortArray sampleBuffer;
00857     unsigned    bytesPerFrame;
00858 };
00859 
00860 
00869 class H323StreamedAudioCodec : public H323FramedAudioCodec
00870 {
00871   PCLASSINFO(H323StreamedAudioCodec, H323FramedAudioCodec);
00872 
00873   public:
00879     H323StreamedAudioCodec(
00880       const OpalMediaFormat & mediaFormat, 
00881       Direction direction,      
00882       unsigned samplesPerFrame, 
00883       unsigned bits             
00884     );
00885 
00891     virtual BOOL EncodeFrame(
00892       BYTE * buffer,    
00893       unsigned & length 
00894     );
00895 
00901     virtual BOOL DecodeFrame(
00902       const BYTE * buffer,  
00903       unsigned length,      
00904       unsigned & written,   
00905       unsigned & samples    
00906     );
00907 
00910     virtual int Encode(short sample) const = 0;
00911 
00914     virtual short Decode(int sample) const = 0;
00915 
00916   protected:
00917     unsigned bitsPerSample;
00918 };
00919 
00920 #endif // NO_H323_AUDIO_CODECS
00921 
00922 
00923 #ifndef NO_H323_VIDEO
00924 
00931 class H323VideoCodec : public H323Codec
00932 {
00933   PCLASSINFO(H323VideoCodec, H323Codec);
00934 
00935   public:
00941     H323VideoCodec(
00942       const OpalMediaFormat & mediaFormat, 
00943       Direction direction      
00944     );
00945 
00946     ~H323VideoCodec();
00947 
00956     virtual BOOL Open(
00957       H323Connection & connection 
00958     );
00959 
00967     virtual void Close();
00968 
00969 
00973     virtual void OnMiscellaneousCommand(
00974       const H245_MiscellaneousCommand_type & type  
00975     );
00976 
00980     virtual void OnMiscellaneousIndication(
00981       const H245_MiscellaneousIndication_type & type  
00982     );
00983 
00984     //    /**Attach the raw data device for use by codec.
00985     //   Note the device provided will be deleted on destruction of the codec.
00986     //   */
00987     // virtual BOOL AttachDevice(
00988     //  H323VideoDevice * device, ///< Device to read/write data
00989     //  BOOL autoDelete = TRUE    ///< Device is to be automatically deleted
00990     // );
00991 
00995     virtual void OnFreezePicture();
00996 
01000     virtual void OnFastUpdatePicture();
01001 
01005     virtual void OnFastUpdateGOB(unsigned firstGOB, unsigned numberOfGOBs);
01006 
01010     virtual void OnFastUpdateMB(int firstGOB, int firstMB, unsigned numberOfMBs);
01011 
01015     virtual void OnVideoIndicateReadyToActivate();
01016 
01020     virtual void OnVideoTemporalSpatialTradeOffCommand(int newQuality);
01021 
01025     virtual void OnVideoTemporalSpatialTradeOffIndication(int newQuality);
01026 
01030     virtual void OnVideoNotDecodedMBs(
01031       unsigned firstMB,
01032       unsigned numberOfMBs,
01033       unsigned temporalReference
01034     );
01035 
01039     virtual void OnLostPartialPicture();
01040 
01044     virtual void OnLostPicture();
01045 
01048     virtual unsigned GetWidth() const { return frameWidth; }
01049 
01052     virtual unsigned GetHeight() const { return frameHeight; }
01053 
01056     virtual void SetTxQualityLevel(int qlevel) {videoQuality = qlevel; }
01057 
01061     virtual void SetTxMinQuality(int qlevel) {videoQMin = qlevel; }
01062 
01066     virtual void SetTxMaxQuality(int qlevel) {videoQMax = qlevel; }
01067 
01070     virtual void SetBackgroundFill(int idle) {fillLevel= idle; }
01071  
01072     enum BitRateModeBits {
01073       None                = 0x00,
01074       DynamicVideoQuality = 0x01,
01075       AdaptivePacketDelay = 0x02
01076     };
01077 
01080     virtual unsigned GetVideoMode(void) {return videoBitRateControlModes;}
01081 
01085     virtual void SetVideoMode(int mode) {videoBitRateControlModes = mode;}
01086 
01094     virtual BOOL SetMaxBitRate(
01095       unsigned bitRate 
01096     );
01097 
01102     virtual unsigned GetMaxBitRate() const { return bitRateHighLimit; }
01103 
01112     virtual BOOL SetTargetFrameTimeMs(
01113       unsigned ms 
01114     );
01115 
01120     virtual void SetGeneralCodecOption(
01121                 const char * opt,    
01122                 int val              
01123         );
01124 
01129     void SendMiscCommand(unsigned command);
01130  
01134    virtual int GetFrameNum() { return frameNum; }
01135 
01136 
01137   protected:
01138 
01139     int frameWidth;
01140     int frameHeight;
01141     int fillLevel;
01142 
01143     // used in h261codec.cxx
01144     unsigned videoBitRateControlModes;
01145     // variables used for video bit rate control
01146     int bitRateHighLimit; // maximum instantaneous bit rate allowed
01147     unsigned oldLength;
01148     PTimeInterval oldTime;
01149     PTimeInterval newTime;
01150     // variables used for dynamic video quality control
01151     int targetFrameTimeMs; //targetFrameTimeMs = 1000 / videoSendFPS
01152     int frameBytes; // accumulate count of bytes per frame
01153     int sumFrameTimeMs, sumAdjFrameTimeMs, sumFrameBytes; // accumulate running average
01154     int videoQMax, videoQMin; // dynamic video quality min/max limits
01155     int videoQuality; // current video encode quality setting, 1..31
01156     PTimeInterval frameStartTime;
01157     PTimeInterval grabInterval;
01158     
01159     int frameNum, packetNum, oldPacketNum;
01160     int framesPerSec;
01161 
01162     PMutex  videoHandlerActive;    
01163 };
01164 
01165 #endif // NO_H323_VIDEO
01166 
01167 #ifndef NO_H323_AUDIO_CODECS
01168 
01170 // The simplest codec is the G.711 PCM codec.
01171 
01174 class H323_ALawCodec : public H323StreamedAudioCodec
01175 {
01176   PCLASSINFO(H323_ALawCodec, H323StreamedAudioCodec)
01177 
01178   public:
01183     H323_ALawCodec(
01184       Direction direction,  
01185       BOOL at56kbps,        
01186       unsigned frameSize    
01187     );
01189 
01190     virtual int   Encode(short sample) const { return EncodeSample(sample); }
01191     virtual short Decode(int   sample) const { return DecodeSample(sample); }
01192 
01193     static int   EncodeSample(short sample);
01194     static short DecodeSample(int   sample);
01195 
01196   protected:
01197     BOOL sevenBit;
01198 };
01199 
01200 
01203 class H323_muLawCodec : public H323StreamedAudioCodec
01204 {
01205   PCLASSINFO(H323_muLawCodec, H323StreamedAudioCodec)
01206 
01207   public:
01212     H323_muLawCodec(
01213       Direction direction,  
01214       BOOL at56kbps,        
01215       unsigned frameSize    
01216     );
01218 
01219     virtual int   Encode(short sample) const { return EncodeSample(sample); }
01220     virtual short Decode(int   sample) const { return DecodeSample(sample); }
01221 
01222     static int   EncodeSample(short sample);
01223     static short DecodeSample(int   sample);
01224 
01225   protected:
01226     BOOL sevenBit;
01227 };
01228 
01229 #endif // NO_H323_AUDIO_CODECS
01230 
01231 
01232 #endif // __CODECS_H
01233 
01234 

Generated on Thu Oct 25 13:41:58 2007 for h323plus by  doxygen 1.5.2