OpenH323 1.18.0
|
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.4 2004/05/12 23:18:44 csoutheren 00029 * Adjusted copyright notices for ffh263 and rfc2190 files 00030 * 00031 * Revision 1.3 2004/04/24 00:41:14 rjongbloed 00032 * Fixed file names in header comment. 00033 * 00034 * Revision 1.2 2004/04/22 22:35:00 csoutheren 00035 * Fixed mispelling of Guilhem Tardy - my apologies to him 00036 * 00037 * Revision 1.1 2004/04/22 22:20:34 csoutheren 00038 * New files for RFC2190 H.263 video codec 00039 * Added RFC 2190 H.263 code as created by Guilhem Tardy and AliceStreet 00040 * Many thanks to them for their contributions. 00041 * 00042 * Revision 1.5 2003/10/31 00:00:00 Guilhem Tardy 00043 * Restored RFC2190 compliance. 00044 * 00045 * Revision 1.4 2003/10/05 00:00:00 Guilhem Tardy 00046 * Reintroduce ffmpeg own packet slicing technique (now working better). 00047 * 00048 * Revision 1.3 2003/08/04 00:03:16 dereksmithies 00049 * Reorganise tests for enabled 00050 * 00051 * Revision 1.2 2003/07/31 05:08:24 dereksmithies 00052 * Switch to manual packet fragment technique. Much more reliable, especially so on windows. 00053 * 00054 * Revision 1.1 2003/07/24 05:23:06 dereksmithies 00055 * Move ffmpeg h263 support to this file, and designate non standard. 00056 * 00057 * Revision 1.12 2003/06/06 05:18:54 dereksmithies 00058 * Fix startup delay bug. Remove all large packets from the network. Improve reliability. 00059 * 00060 * Revision 1.11 2003/05/27 09:22:55 dereksmithies 00061 * Updates for code revisions in h263 codec 00062 * 00063 * Revision 1.10 2003/05/14 13:47:58 rjongbloed 00064 * Removed static "initialisation" function as this should be done 00065 * internally and not in the application. 00066 * 00067 * Revision 1.9 2003/05/05 11:59:21 robertj 00068 * Changed to use autoconf style selection of options and subsystems. 00069 * 00070 * Revision 1.8 2003/05/02 04:22:10 craigs 00071 * Added lots of extra H.263 support 00072 * 00073 * Revision 1.7 2003/04/27 09:16:38 rogerh 00074 * use PBYTE_ORDER instead of endian.h 00075 * 00076 * Revision 1.6 2003/04/21 21:50:22 dereks 00077 * Implement suggestion from Guilhem Tardy. Many thanks. 00078 * 00079 * Revision 1.5 2003/04/16 04:26:57 dereks 00080 * Initial release of h263 codec, which utilises the ffmpeg library. 00081 * Thanks to Guilhem Tardy, and to AliceStreet. 00082 * 00083 * Revision 1.4 2002/09/16 01:14:15 robertj 00084 * Added #define so can select if #pragma interface/implementation is used on 00085 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00086 * 00087 * Revision 1.3 2002/09/03 06:19:36 robertj 00088 * Normalised the multi-include header prevention ifdef/define symbol. 00089 * 00090 * Revision 1.2 2002/08/05 10:03:47 robertj 00091 * Cosmetic changes to normalise the usage of pragma interface/implementation. 00092 * 00093 * Revision 1.1 2002/05/19 22:32:46 dereks 00094 * Initial release of stub file for h263 codec. Thanks Guilhem Tardy. 00095 * 00096 * 00097 * 00098 */ 00099 00100 /* 00101 * Initial release notes from Guilhem Tardy:: 00102 * 00103 * Added support for video capabilities & codec, only tested under Linux! 00104 * The code for varying bit rate is copied from h261codec.cxx, 00105 * until it is moved to a separate file common to both video codecs. 00106 * 00107 */ 00108 00109 #ifndef __OPAL_FFH263CODEC_H 00110 #define __OPAL_FFH263CODEC_H 00111 00112 #ifdef P_USE_PRAGMA 00113 #pragma interface 00114 #endif 00115 00116 #ifdef H323_RFC2190_AVCODEC 00117 struct AVCodec; 00118 struct AVCodecContext; 00119 struct AVFrame; 00120 00122 00125 class H323_RFC2190_H263Capability : public H323VideoCapability 00126 { 00127 PCLASSINFO(H323_RFC2190_H263Capability, H323VideoCapability) 00128 00129 public: 00134 H323_RFC2190_H263Capability( 00135 unsigned sqcifMPI = 1, // {1..3600 units seconds/frame, 1..32 units 1/29.97 Hz} 00136 unsigned qcifMPI = 2, 00137 unsigned cifMPI = 4, 00138 unsigned cif4MPI = 8, 00139 unsigned cif16MPI = 32, 00140 unsigned maxBitRate = 400, 00141 BOOL unrestrictedVector = FALSE, 00142 BOOL arithmeticCoding = FALSE, // not supported 00143 BOOL advancedPrediction = FALSE, 00144 BOOL pbFrames = FALSE, 00145 BOOL temporalSpatialTradeOff = FALSE, // not supported 00146 unsigned hrd_B = 0, // not supported 00147 unsigned bppMaxKb = 0, // not supported 00148 unsigned slowSqcifMPI = 0, 00149 unsigned slowQcifMPI = 0, 00150 unsigned slowCifMPI = 0, 00151 unsigned slowCif4MPI = 0, 00152 unsigned slowCif16MPI = 0, 00153 BOOL errorCompensation = FALSE // not supported 00154 ); 00156 00161 virtual PObject * Clone() const; 00163 00168 Comparison Compare(const PObject & obj) const; 00170 00179 virtual unsigned GetSubType() const; 00180 00183 virtual PString GetFormatName() const; 00185 00195 virtual BOOL OnSendingPDU( 00196 H245_VideoCapability & pdu 00197 ) const; 00198 00206 virtual BOOL OnSendingPDU( 00207 H245_VideoMode & pdu 00208 ) const; 00209 00217 virtual BOOL OnReceivedPDU( 00218 const H245_VideoCapability & pdu 00219 ); 00220 00223 virtual H323Codec * CreateCodec( 00224 H323Codec::Direction direction 00225 ) const; 00226 00229 unsigned GetSQCIFMPI() const 00230 { return sqcifMPI; } 00231 00234 unsigned GetQCIFMPI() const 00235 { return qcifMPI; } 00236 00239 unsigned GetCIFMPI() const 00240 { return cifMPI; } 00241 00244 unsigned GetCIF4MPI() const 00245 { return cif4MPI; } 00246 00249 unsigned GetCIF16MPI() const 00250 { return cif16MPI; } 00251 00254 unsigned GetMaxBitRate() const 00255 { return maxBitRate; } 00256 00259 BOOL GetUnrestrictedVectorCapability() const 00260 { return unrestrictedVector; } 00261 00264 BOOL GetArithmeticCodingCapability() const 00265 { return arithmeticCoding; } 00266 00269 BOOL GetAdvancedPredictionCapability() const 00270 { return advancedPrediction; } 00271 00274 BOOL GetPbFramesCapability() const 00275 { return pbFrames; } 00276 00279 BOOL GetTemporalSpatialTradeOffCapability() const 00280 { return temporalSpatialTradeOff; } 00281 00284 BOOL GetHrd_B() const 00285 { return hrd_B; } 00286 00289 BOOL GetBppMaxKb() const 00290 { return bppMaxKb; } 00291 00294 unsigned GetSlowSQCIFMPI() const 00295 { return (sqcifMPI<0?-sqcifMPI:0); } 00296 00299 unsigned GetSlowQCIFMPI() const 00300 { return (qcifMPI<0?-qcifMPI:0); } 00301 00304 unsigned GetSlowCIFMPI() const 00305 { return (cifMPI<0?-cifMPI:0); } 00306 00309 unsigned GetSlowCIF4MPI() const 00310 { return (cif4MPI<0?-cif4MPI:0); } 00311 00314 unsigned GetSlowCIF16MPI() const 00315 { return (cif16MPI<0?-cif16MPI:0); } 00316 00319 BOOL GetErrorCompensationCapability() const 00320 { return errorCompensation; } 00322 00323 protected: 00324 00325 signed sqcifMPI; // {1..3600 units seconds/frame, 1..32 units 1/29.97 Hz} 00326 signed qcifMPI; 00327 signed cifMPI; 00328 signed cif4MPI; 00329 signed cif16MPI; 00330 00331 unsigned maxBitRate; // units of bit/s 00332 00333 BOOL unrestrictedVector; 00334 BOOL arithmeticCoding; 00335 BOOL advancedPrediction; 00336 BOOL pbFrames; 00337 BOOL temporalSpatialTradeOff; 00338 00339 long unsigned hrd_B; // units of 128 bits 00340 unsigned bppMaxKb; // units of 1024 bits 00341 00342 BOOL errorCompensation; 00343 }; 00344 00346 00347 class H263Packet : public PObject 00348 { 00349 PCLASSINFO(H263Packet, PObject) 00350 00351 public: 00352 00353 H263Packet() { data_size = hdr_size = 0; hdr = data = NULL; }; 00354 ~H263Packet() {}; 00355 00356 void Store(void *data, int data_size, void *hdr, int hdr_size); 00357 BOOL Read(unsigned & length, RTP_DataFrame & frame); 00358 00359 private: 00360 00361 void *data; 00362 int data_size; 00363 void *hdr; 00364 int hdr_size; 00365 }; 00366 00367 PDECLARE_LIST(H263PacketList, H263Packet) 00368 #if 0 00369 { 00370 #endif 00371 }; 00372 00374 00377 class H323_RFC2190_H263Codec : public H323VideoCodec 00378 { 00379 PCLASSINFO(H323_RFC2190_H263Codec, H323VideoCodec) 00380 00381 public: 00384 H323_RFC2190_H263Codec( 00385 Direction direction, 00386 signed sqcifMPI, 00387 signed qcifMPI, 00388 signed cifMPI, 00389 signed cif4MPI, 00390 signed cif16MPI, 00391 unsigned maxBitRate, 00392 BOOL unrestrictedVector, 00393 BOOL arithmeticCoding, 00394 BOOL advancedPrediction, 00395 BOOL pbFrames 00396 ); 00397 00398 ~H323_RFC2190_H263Codec(); 00399 00416 virtual BOOL Read( 00417 BYTE * buffer, 00418 unsigned & length, 00419 RTP_DataFrame & rtpFrame 00420 ); 00421 00434 virtual BOOL Write( 00435 const BYTE * buffer, 00436 unsigned length, 00437 const RTP_DataFrame & rtp, 00438 unsigned & written 00439 ); 00440 00443 virtual unsigned GetFrameRate() const { return rtpTimestampDelta; } 00444 00447 void SetTxQualityLevel(int qLevel); 00448 00452 virtual void SetTxMinQuality(int qlevel); 00453 00457 virtual void SetTxMaxQuality(int qlevel); 00458 00462 void SetBackgroundFill(int fillLevel); 00463 00467 virtual void SetVideoMode(unsigned mode); 00468 00473 virtual BOOL SetMaxBitRate(unsigned bitRate); 00474 00478 virtual void OnVideoTemporalSpatialTradeOff(); 00479 00483 virtual void OnLostPartialPicture(); 00484 00488 virtual void OnLostPicture(); 00489 00495 static void RtpCallback(void *data, int data_size, 00496 void *hdr, int hdr_size, void *priv_data); 00497 00498 protected: 00499 00500 BOOL Resize(int width, int height); 00501 00502 BOOL RenderFrame(const void *buffer); 00503 BOOL RenderFrame(const AVFrame *pict); 00504 00505 BOOL OpenCodec(); 00506 00507 void CloseCodec(); 00508 00509 H263PacketList encodedPackets; 00510 H263PacketList unusedPackets; 00511 00512 PBYTEArray encFrameBuffer; 00513 PBYTEArray rawFrameBuffer; 00514 00515 PINDEX encFrameLen; 00516 PINDEX rawFrameLen; 00517 00518 AVCodec *codec; 00519 AVCodecContext *context; 00520 AVFrame *picture; 00521 00522 PTime lastFrameTime; 00523 unsigned rtpTimestampDelta; 00524 PTime lastPacketTime; 00525 PINDEX lastPacketBits; 00526 00527 enum StdSize {UnknownStdSize, SQCIF = 1, QCIF, CIF, CIF4, CIF16, NumStdSizes}; 00528 00529 static int GetStdSize(int width, int height); // 00530 static int GetStdWidth (StdSize size); 00531 static int GetStdHeight (StdSize size); 00532 00533 signed videoFrameRate[NumStdSizes]; 00534 StdSize videoSize; 00535 BOOL unrestrictedVector; 00536 BOOL arithmeticCoding; 00537 BOOL advancedPrediction; 00538 BOOL pbFrames; 00539 }; 00540 00541 #endif // H323_AVCODEC 00542 00543 #endif // __OPAL_FFH263CODEC_H 00544 00545