rfc2190avcodec.h

Go to the documentation of this file.
00001 /*
00002  * rfc2190avcodec.h
00003  *
00004  * H.323 protocol handler
00005  *
00006  * Open H323 Library
00007  *
00008  * Copyright (c) 2001 March Networks Corporation
00009  * Copyright (c) 1999-2000 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 H323 Library.
00022  *
00023  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00024  *
00025  * Contributor(s): Guilhem Tardy (gtardy@salyens.com)
00026  *
00027  * $Log: rfc2190avcodec.h,v $
00028  * Revision 1.6  2006/08/01 06:17:50  csoutheren
00029  * Fix bit rate control units
00030  * Add access function on code for max bit rate
00031  * Thanks to Paolo Amadini
00032  *
00033  * Revision 1.5  2006/07/19 07:18:17  csoutheren
00034  * Fixed problem with timing in H.263 video codec
00035  * Thanks to Paolo Amadini
00036  *
00037  * Revision 1.4  2004/05/12 23:18:44  csoutheren
00038  * Adjusted copyright notices for ffh263 and rfc2190 files
00039  *
00040  * Revision 1.3  2004/04/24 00:41:14  rjongbloed
00041  * Fixed file names in header comment.
00042  *
00043  * Revision 1.2  2004/04/22 22:35:00  csoutheren
00044  * Fixed mispelling of Guilhem Tardy - my apologies to him
00045  *
00046  * Revision 1.1  2004/04/22 22:20:34  csoutheren
00047  * New files for RFC2190 H.263 video codec
00048  * Added RFC 2190 H.263 code as created by Guilhem Tardy and AliceStreet
00049  * Many thanks to them for their contributions.
00050  *
00051  * Revision 1.5  2003/10/31 00:00:00  Guilhem Tardy
00052  * Restored RFC2190 compliance.
00053  *
00054  * Revision 1.4  2003/10/05 00:00:00  Guilhem Tardy
00055  * Reintroduce ffmpeg own packet slicing technique (now working better).
00056  *
00057  * Revision 1.3  2003/08/04 00:03:16  dereksmithies
00058  * Reorganise tests for enabled
00059  *
00060  * Revision 1.2  2003/07/31 05:08:24  dereksmithies
00061  * Switch to manual packet fragment technique. Much more reliable, especially so on windows.
00062  *
00063  * Revision 1.1  2003/07/24 05:23:06  dereksmithies
00064  * Move ffmpeg h263 support to this file, and designate non standard.
00065  *
00066  * Revision 1.12  2003/06/06 05:18:54  dereksmithies
00067  * Fix startup delay bug. Remove all large packets from the network. Improve reliability.
00068  *
00069  * Revision 1.11  2003/05/27 09:22:55  dereksmithies
00070  * Updates for code revisions in h263 codec
00071  *
00072  * Revision 1.10  2003/05/14 13:47:58  rjongbloed
00073  * Removed static "initialisation" function as this should be done
00074  *   internally and not in the application.
00075  *
00076  * Revision 1.9  2003/05/05 11:59:21  robertj
00077  * Changed to use autoconf style selection of options and subsystems.
00078  *
00079  * Revision 1.8  2003/05/02 04:22:10  craigs
00080  * Added lots of extra H.263 support
00081  *
00082  * Revision 1.7  2003/04/27 09:16:38  rogerh
00083  * use PBYTE_ORDER instead of endian.h
00084  *
00085  * Revision 1.6  2003/04/21 21:50:22  dereks
00086  * Implement suggestion from Guilhem Tardy. Many thanks.
00087  *
00088  * Revision 1.5  2003/04/16 04:26:57  dereks
00089  * Initial release of h263 codec, which utilises the ffmpeg library.
00090  * Thanks to Guilhem Tardy, and to AliceStreet.
00091  *
00092  * Revision 1.4  2002/09/16 01:14:15  robertj
00093  * Added #define so can select if #pragma interface/implementation is used on
00094  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00095  *
00096  * Revision 1.3  2002/09/03 06:19:36  robertj
00097  * Normalised the multi-include header prevention ifdef/define symbol.
00098  *
00099  * Revision 1.2  2002/08/05 10:03:47  robertj
00100  * Cosmetic changes to normalise the usage of pragma interface/implementation.
00101  *
00102  * Revision 1.1  2002/05/19 22:32:46  dereks
00103  * Initial release of stub file for h263 codec. Thanks Guilhem Tardy.
00104  *
00105  *
00106  *
00107  */
00108  
00109 /*
00110  * Initial release notes from Guilhem Tardy::
00111  *
00112  * Added support for video capabilities & codec, only tested under Linux!
00113  * The code for varying bit rate is copied from h261codec.cxx,
00114  * until it is moved to a separate file common to both video codecs.
00115  *
00116  */
00117 
00118 #ifndef __OPAL_FFH263CODEC_H
00119 #define __OPAL_FFH263CODEC_H
00120 
00121 #ifdef P_USE_PRAGMA
00122 #pragma interface
00123 #endif
00124 
00125 #ifdef H323_RFC2190_AVCODEC
00126 struct AVCodec;
00127 struct AVCodecContext;
00128 struct AVFrame;
00129 
00130 #include <ptclib/delaychan.h>
00131 
00133 
00136 class H323_RFC2190_H263Capability : public H323VideoCapability
00137 {
00138   PCLASSINFO(H323_RFC2190_H263Capability, H323VideoCapability)
00139 
00140   public:
00145     H323_RFC2190_H263Capability(
00146       unsigned sqcifMPI = 1,    // {1..3600 units seconds/frame, 1..32 units 1/29.97 Hz}
00147       unsigned qcifMPI = 2,
00148       unsigned cifMPI = 4,
00149       unsigned cif4MPI = 8,
00150       unsigned cif16MPI = 32,
00151       unsigned maxBitRate = 400,
00152       BOOL unrestrictedVector = FALSE,
00153       BOOL arithmeticCoding = FALSE, // not supported
00154       BOOL advancedPrediction = FALSE,
00155       BOOL pbFrames = FALSE,
00156       BOOL temporalSpatialTradeOff = FALSE, // not supported
00157       unsigned hrd_B = 0, // not supported
00158       unsigned bppMaxKb = 0, // not supported
00159       unsigned slowSqcifMPI = 0,
00160       unsigned slowQcifMPI = 0,
00161       unsigned slowCifMPI = 0,
00162       unsigned slowCif4MPI = 0,
00163       unsigned slowCif16MPI = 0,
00164       BOOL errorCompensation = FALSE // not supported
00165     );
00167 
00172     virtual PObject * Clone() const;
00174 
00179     Comparison Compare(const PObject & obj) const;
00181 
00190     virtual unsigned GetSubType() const;
00191 
00194     virtual PString GetFormatName() const;
00196 
00206     virtual BOOL OnSendingPDU(
00207       H245_VideoCapability & pdu  
00208     ) const;
00209 
00217     virtual BOOL OnSendingPDU(
00218       H245_VideoMode & pdu  
00219     ) const;
00220 
00228     virtual BOOL OnReceivedPDU(
00229       const H245_VideoCapability & pdu  
00230     );
00231 
00234     virtual H323Codec * CreateCodec(
00235       H323Codec::Direction direction  
00236     ) const;
00237 
00240     unsigned GetSQCIFMPI() const
00241       { return sqcifMPI; }
00242 
00245     unsigned GetQCIFMPI() const
00246       { return qcifMPI; }
00247 
00250     unsigned GetCIFMPI() const
00251       { return cifMPI; }
00252 
00255     unsigned GetCIF4MPI() const
00256       { return cif4MPI; }
00257 
00260     unsigned GetCIF16MPI() const
00261       { return cif16MPI; }
00262 
00265     unsigned GetMaxBitRate() const
00266       { return maxBitRate; }
00267 
00270     BOOL GetUnrestrictedVectorCapability() const
00271       { return unrestrictedVector; }
00272 
00275     BOOL GetArithmeticCodingCapability() const
00276       { return arithmeticCoding; }
00277 
00280     BOOL GetAdvancedPredictionCapability() const
00281       { return advancedPrediction; }
00282 
00285     BOOL GetPbFramesCapability() const
00286       { return pbFrames; }
00287 
00290     BOOL GetTemporalSpatialTradeOffCapability() const
00291       { return temporalSpatialTradeOff; }
00292 
00295     BOOL GetHrd_B() const
00296       { return hrd_B; }
00297 
00300     BOOL GetBppMaxKb() const
00301       { return bppMaxKb; }
00302 
00305     unsigned GetSlowSQCIFMPI() const
00306       { return (sqcifMPI<0?-sqcifMPI:0); }
00307 
00310     unsigned GetSlowQCIFMPI() const
00311       { return (qcifMPI<0?-qcifMPI:0); }
00312 
00315     unsigned GetSlowCIFMPI() const
00316       { return (cifMPI<0?-cifMPI:0); }
00317 
00320     unsigned GetSlowCIF4MPI() const
00321       { return (cif4MPI<0?-cif4MPI:0); }
00322 
00325     unsigned GetSlowCIF16MPI() const
00326       { return (cif16MPI<0?-cif16MPI:0); }
00327 
00330     BOOL GetErrorCompensationCapability() const
00331       { return errorCompensation; }
00333 
00334 protected:
00335 
00336     signed sqcifMPI;            // {1..3600 units seconds/frame, 1..32 units 1/29.97 Hz}
00337     signed qcifMPI;
00338     signed cifMPI;
00339     signed cif4MPI;
00340     signed cif16MPI;
00341 
00342     unsigned maxBitRate;        // units of bit/s
00343 
00344     BOOL     unrestrictedVector;
00345     BOOL     arithmeticCoding;
00346     BOOL     advancedPrediction;
00347     BOOL     pbFrames;
00348     BOOL     temporalSpatialTradeOff;
00349 
00350     long unsigned hrd_B;        // units of 128 bits
00351     unsigned bppMaxKb;          // units of 1024 bits
00352 
00353     BOOL     errorCompensation;
00354 };
00355 
00357 
00358 class H263Packet : public PObject
00359 {
00360   PCLASSINFO(H263Packet, PObject)
00361 
00362   public:
00363 
00364     H263Packet() { data_size = hdr_size = 0; hdr = data = NULL; };
00365     ~H263Packet() {};
00366 
00367     void Store(void *data, int data_size, void *hdr, int hdr_size);
00368     BOOL Read(unsigned & length, RTP_DataFrame & frame);
00369 
00370   private:
00371 
00372     void *data;
00373     int data_size;
00374     void *hdr;
00375     int hdr_size;
00376 };
00377 
00378 PDECLARE_LIST(H263PacketList, H263Packet)
00379 #if 0
00380 {
00381 #endif
00382 };
00383 
00385 
00388 class H323_RFC2190_H263Codec : public H323VideoCodec
00389 {
00390   PCLASSINFO(H323_RFC2190_H263Codec, H323VideoCodec)
00391 
00392   public:
00395     H323_RFC2190_H263Codec(
00396       Direction direction,      
00397       signed sqcifMPI,          
00398       signed qcifMPI,
00399       signed cifMPI,
00400       signed cif4MPI,
00401       signed cif16MPI,
00402       unsigned maxBitRate, 
00403       BOOL unrestrictedVector,
00404       BOOL arithmeticCoding,
00405       BOOL advancedPrediction,
00406       BOOL pbFrames
00407     );
00408 
00409     ~H323_RFC2190_H263Codec();
00410 
00427     virtual BOOL Read(
00428       BYTE * buffer,            
00429       unsigned & length,        
00430       RTP_DataFrame & rtpFrame  
00431     );
00432 
00445     virtual BOOL Write(
00446       const BYTE * buffer,        
00447       unsigned length,            
00448       const RTP_DataFrame & rtp,  
00449       unsigned & written          
00450     );
00451 
00454     virtual unsigned GetFrameRate() const { return rtpTimestampDelta; }
00455 
00458     void SetTxQualityLevel(int qLevel);
00459  
00463     virtual void SetTxMinQuality(int qlevel);
00464 
00468     virtual void SetTxMaxQuality(int qlevel);
00469 
00473     void SetBackgroundFill(int fillLevel);
00474 
00478     virtual void SetVideoMode(unsigned mode);
00479 
00491     virtual BOOL SetMaxBitRate(unsigned bitRate);
00492 
00497     virtual unsigned GetMaxBitRate() const { return bitRateHighLimit; }
00498 
00502     virtual void OnVideoTemporalSpatialTradeOff();
00503 
00507     virtual void OnLostPartialPicture();
00508 
00512     virtual void OnLostPicture();
00513 
00519     static void RtpCallback(void *data, int data_size,
00520                             void *hdr, int hdr_size, void *priv_data);
00521 
00522   protected:
00523 
00524     BOOL Resize(int width, int height);
00525 
00526     BOOL RenderFrame(const void *buffer);
00527     BOOL RenderFrame(const AVFrame *pict);
00528 
00529     BOOL OpenCodec();
00530 
00531     void CloseCodec();
00532 
00533     H263PacketList encodedPackets;
00534     H263PacketList unusedPackets;
00535 
00536     PBYTEArray encFrameBuffer;
00537     PBYTEArray rawFrameBuffer;
00538 
00539     PINDEX encFrameLen;
00540     PINDEX rawFrameLen;
00541 
00542     AVCodec        *codec;
00543     AVCodecContext *context;
00544     AVFrame        *picture;
00545 
00546     PTime lastFrameTime;
00547     unsigned rtpTimestampDelta;
00548     PAdaptiveDelay packetDelay;
00549     PTime lastPacketTime;
00550     PINDEX lastPacketBits;
00551 
00552     enum StdSize {UnknownStdSize, SQCIF = 1, QCIF, CIF, CIF4, CIF16, NumStdSizes};
00553 
00554     static int GetStdSize(int width, int height); //
00555     static int GetStdWidth (StdSize size);
00556     static int GetStdHeight (StdSize size);
00557 
00558     signed videoFrameRate[NumStdSizes]; 
00559     StdSize videoSize;
00560     BOOL unrestrictedVector;
00561     BOOL arithmeticCoding;
00562     BOOL advancedPrediction;
00563     BOOL pbFrames;
00564 };
00565 
00566 #endif // H323_AVCODEC
00567 
00568 #endif // __OPAL_FFH263CODEC_H
00569 
00570 

Generated on Wed Feb 6 09:02:44 2008 for OpenH323 by  doxygen 1.5.4