00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef __OPAL_H263CODEC_H
00046 #define __OPAL_H263CODEC_H
00047
00048 #ifdef P_USE_PRAGMA
00049 #pragma interface
00050 #endif
00051
00052 #include <opal/buildopts.h>
00053
00054 #ifndef NO_OPAL_VIDEO
00055
00056 #ifdef RFC2190_AVCODEC
00057
00058 #ifndef NO_H323
00059 #include <h323/h323caps.h>
00060 #endif
00061
00062 #include <codec/vidcodec.h>
00063 #include <rtp/rtp.h>
00064
00065 #define OPAL_H263 "H.263"
00066
00067 #define OPAL_H263_SQCIF "H.263(SQCIF)"
00068 #define OPAL_H263_QCIF "H.263(QCIF)"
00069 #define OPAL_H263_CIF "H.263(CIF)"
00070
00071 extern const OpalVideoFormat & GetOpalH263();
00072
00073 #define OpalH263 GetOpalH263()
00074
00075 struct AVCodec;
00076 struct AVCodecContext;
00077 struct AVFrame;
00078
00079 namespace PWLibStupidLinkerHacks {
00080 extern int rfc2190h263Loader;
00081 };
00083
00084 #ifndef NO_H323
00085
00088 class H323_H263Capability : public H323VideoCapability
00089 {
00090 PCLASSINFO(H323_H263Capability, H323VideoCapability)
00091
00092 public:
00097 H323_H263Capability(
00098 unsigned sqcifMPI = 1,
00099 unsigned qcifMPI = 2,
00100 unsigned cifMPI = 4,
00101 unsigned cif4MPI = 8,
00102 unsigned cif16MPI = 32,
00103 unsigned maxBitRate = 400,
00104 BOOL unrestrictedVector = FALSE,
00105 BOOL arithmeticCoding = FALSE,
00106 BOOL advancedPrediction = FALSE,
00107 BOOL pbFrames = FALSE,
00108 BOOL temporalSpatialTradeOff = FALSE,
00109 unsigned hrd_B = 0,
00110 unsigned bppMaxKb = 0,
00111 unsigned slowSqcifMPI = 0,
00112 unsigned slowQcifMPI = 0,
00113 unsigned slowCifMPI = 0,
00114 unsigned slowCif4MPI = 0,
00115 unsigned slowCif16MPI = 0,
00116 BOOL errorCompensation = FALSE
00117 );
00119
00124 virtual PObject * Clone() const;
00126
00131 Comparison Compare(const PObject & obj) const;
00133
00142 virtual unsigned GetSubType() const;
00143
00146 virtual PString GetFormatName() const;
00148
00158 virtual BOOL OnSendingPDU(
00159 H245_VideoCapability & pdu
00160 ) const;
00161
00169 virtual BOOL OnSendingPDU(
00170 H245_VideoMode & pdu
00171 ) const;
00172
00180 virtual BOOL OnReceivedPDU(
00181 const H245_VideoCapability & pdu
00182 );
00183
00186 unsigned GetSQCIFMPI() const
00187 { return sqcifMPI; }
00188
00191 unsigned GetQCIFMPI() const
00192 { return qcifMPI; }
00193
00196 unsigned GetCIFMPI() const
00197 { return cifMPI; }
00198
00201 unsigned GetCIF4MPI() const
00202 { return cif4MPI; }
00203
00206 unsigned GetCIF16MPI() const
00207 { return cif16MPI; }
00208
00211 unsigned GetMaxBitRate() const
00212 { return maxBitRate; }
00213
00216 BOOL GetUnrestrictedVectorCapability() const
00217 { return unrestrictedVector; }
00218
00221 BOOL GetArithmeticCodingCapability() const
00222 { return arithmeticCoding; }
00223
00226 BOOL GetAdvancedPredictionCapability() const
00227 { return advancedPrediction; }
00228
00231 BOOL GetPbFramesCapability() const
00232 { return pbFrames; }
00233
00236 BOOL GetTemporalSpatialTradeOffCapability() const
00237 { return temporalSpatialTradeOff; }
00238
00241 BOOL GetHrd_B() const
00242 { return hrd_B; }
00243
00246 BOOL GetBppMaxKb() const
00247 { return bppMaxKb; }
00248
00251 unsigned GetSlowSQCIFMPI() const
00252 { return (sqcifMPI<0?-sqcifMPI:0); }
00253
00256 unsigned GetSlowQCIFMPI() const
00257 { return (qcifMPI<0?-qcifMPI:0); }
00258
00261 unsigned GetSlowCIFMPI() const
00262 { return (cifMPI<0?-cifMPI:0); }
00263
00266 unsigned GetSlowCIF4MPI() const
00267 { return (cif4MPI<0?-cif4MPI:0); }
00268
00271 unsigned GetSlowCIF16MPI() const
00272 { return (cif16MPI<0?-cif16MPI:0); }
00273
00276 BOOL GetErrorCompensationCapability() const
00277 { return errorCompensation; }
00279
00280 protected:
00281
00282 signed sqcifMPI;
00283 signed qcifMPI;
00284 signed cifMPI;
00285 signed cif4MPI;
00286 signed cif16MPI;
00287
00288 unsigned maxBitRate;
00289
00290 BOOL unrestrictedVector;
00291 BOOL arithmeticCoding;
00292 BOOL advancedPrediction;
00293 BOOL pbFrames;
00294 BOOL temporalSpatialTradeOff;
00295
00296 long unsigned hrd_B;
00297 unsigned bppMaxKb;
00298
00299 BOOL errorCompensation;
00300 };
00301
00304 #define OPAL_REGISTER_H263_H323 \
00305 H323_REGISTER_CAPABILITY_FUNCTION(H323_H263_SQCIF_QCIF_CIF_Capability, OPAL_H263, H323_NO_EP_VAR) \
00306 { return new H323_H263Capability(1, 1, 2, 0, 0, 6217); } \
00307 H323_REGISTER_CAPABILITY_FUNCTION(H323_H263_SQCIF_Capability, OPAL_H263_SQCIF, H323_NO_EP_VAR) \
00308 { return new H323_H263Capability(1, 0, 0, 0, 0, 6217); } \
00309 H323_REGISTER_CAPABILITY_FUNCTION(H323_H263_QCIF_Capability, OPAL_H263_QCIF, H323_NO_EP_VAR) \
00310 { return new H323_H263Capability(0, 1, 0, 0, 0, 6217); } \
00311 H323_REGISTER_CAPABILITY_FUNCTION(H323_H263_CIF_Capability, OPAL_H263_CIF, H323_NO_EP_VAR) \
00312 { return new H323_H263Capability(0, 0, 2, 0, 0, 6217); }
00313
00314 #else // ifndef NO_H323
00315
00316 #define OPAL_REGISTER_H263_H323
00317
00318 #endif // ifndef NO_H323
00319
00321
00322 class H263Packet : public PObject
00323 {
00324 PCLASSINFO(H263Packet, PObject)
00325
00326 public:
00327
00328 H263Packet() { data_size = hdr_size = 0; hdr = data = NULL; };
00329 ~H263Packet() {};
00330
00331 void Store(void *data, int data_size, void *hdr, int hdr_size);
00332 BOOL Read(unsigned & length, RTP_DataFrame & frame);
00333
00334 private:
00335
00336 void *data;
00337 int data_size;
00338 void *hdr;
00339 int hdr_size;
00340 };
00341
00342 PDECLARE_LIST(H263PacketList, H263Packet)
00343 #if 0
00344 {
00345 #endif
00346 };
00347
00349
00350 class Opal_H263_YUV420P : public OpalVideoTranscoder {
00351 public:
00352 Opal_H263_YUV420P();
00353 ~Opal_H263_YUV420P();
00354 virtual PINDEX GetOptimalDataFrameSize(BOOL input) const;
00355 virtual BOOL ConvertFrames(const RTP_DataFrame & src, RTP_DataFrameList & dst);
00356
00357 protected:
00358 BOOL OpenCodec();
00359 void CloseCodec();
00360
00361 PBYTEArray encFrameBuffer;
00362
00363 AVCodec *codec;
00364 AVCodecContext *context;
00365 AVFrame *picture;
00366
00367 int frameNum;
00368 };
00369
00370 class Opal_YUV420P_H263 : public OpalVideoTranscoder {
00371 public:
00372 Opal_YUV420P_H263();
00373 ~Opal_YUV420P_H263();
00374 virtual PINDEX GetOptimalDataFrameSize(BOOL input) const;
00375 virtual BOOL ConvertFrames(const RTP_DataFrame & src, RTP_DataFrameList & dst);
00376
00377 static void RtpCallback(void *data, int data_size,
00378 void *hdr, int hdr_size, void *priv_data);
00379
00380 protected:
00381 BOOL OpenCodec();
00382 void CloseCodec();
00383
00384 H263PacketList encodedPackets;
00385 H263PacketList unusedPackets;
00386
00387 PBYTEArray encFrameBuffer;
00388 PBYTEArray rawFrameBuffer;
00389
00390 PINDEX encFrameLen;
00391 PINDEX rawFrameLen;
00392
00393 AVCodec *codec;
00394 AVCodecContext *context;
00395 AVFrame *picture;
00396
00397 int videoQMax, videoQMin;
00398 int videoQuality;
00399 int frameNum;
00400
00401 enum StdSize {UnknownStdSize, SQCIF = 1, QCIF, CIF, CIF4, CIF16, NumStdSizes};
00402 static int GetStdSize(int width, int height);
00403 };
00404
00406
00407 #define OPAL_REGISTER_H263() \
00408 OPAL_REGISTER_H263_H323 \
00409 OpalTranscoderFactory::Worker<Opal_H263_YUV420P> Opal_H263_YUV420P(OpalCreateMediaFormatPair(OpalH263, OpalYUV420P)); \
00410 OpalTranscoderFactory::Worker<Opal_YUV420P_H263> Opal_YUV420P_H263(OpalCreateMediaFormatPair(OpalYUV420P, OpalH263))
00411
00413
00414 #endif // RFC2190_AVCODEC
00415
00416 #endif // NO_OPAL_VIDEO
00417
00418 #endif // __OPAL_H263CODEC_H