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
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
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
00341
00342
00343
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 , int ) { 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;
00579
00580 PChannel * rawDataChannel;
00581 BOOL deleteChannel;
00582 PMutex rawChannelMutex;
00583
00584 PINDEX lastSequenceNumber;
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 ) {}
00680
00684 virtual int GetTxQualityLevel(int ) { 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 *
00713 ) {};
00714 #endif
00715
00716 protected:
00717 unsigned samplesPerFrame;
00718
00719 SilenceDetectionMode silenceDetectMode;
00720
00721 unsigned signalDeadbandFrames;
00722 unsigned silenceDeadbandFrames;
00723 unsigned adaptiveThresholdFrames;
00724
00725 BOOL inTalkBurst;
00726 unsigned framesReceived;
00727 unsigned levelThreshold;
00728 unsigned signalMinimum;
00729 unsigned silenceMaximum;
00730 unsigned signalFramesReceived;
00731 unsigned silenceFramesReceived;
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;
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
00985
00986
00987
00988
00989
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
01144 unsigned videoBitRateControlModes;
01145
01146 int bitRateHighLimit;
01147 unsigned oldLength;
01148 PTimeInterval oldTime;
01149 PTimeInterval newTime;
01150
01151 int targetFrameTimeMs;
01152 int frameBytes;
01153 int sumFrameTimeMs, sumAdjFrameTimeMs, sumFrameBytes;
01154 int videoQMax, videoQMin;
01155 int videoQuality;
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
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