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 #ifndef __CODECS_H
00294 #define __CODECS_H
00295
00296 #ifdef P_USE_PRAGMA
00297 #pragma interface
00298 #endif
00299
00300
00301 #include <mediafmt.h>
00302 #include <rtp.h>
00303 #include <channels.h>
00304 #include "openh323buildopts.h"
00305
00306
00307
00308
00309
00310
00311
00312 class H245_MiscellaneousCommand_type;
00313 class H245_MiscellaneousIndication_type;
00314 class H323Connection;
00315
00316
00317
00319
00327 class H323Codec : public PObject
00328 {
00329 PCLASSINFO(H323Codec, PObject);
00330
00331 public:
00332 enum Direction {
00333 Encoder,
00334 Decoder
00335 };
00336
00337 H323Codec(
00338 const char * mediaFormat,
00339 Direction direction
00340 );
00341
00342
00355 virtual BOOL Open(
00356 H323Connection & connection
00357 );
00358
00361 virtual void Close() = 0;
00362
00380 virtual BOOL Read(
00381 BYTE * buffer,
00382 unsigned & length,
00383 RTP_DataFrame & rtpFrame
00384 ) = 0;
00385
00397 virtual BOOL Write(
00398 const BYTE * buffer,
00399 unsigned length,
00400 const RTP_DataFrame & frame,
00401 unsigned & written
00402 ) = 0;
00403
00406 virtual unsigned GetFrameRate() const;
00407
00411 virtual void OnFlowControl(
00412 long bitRateRestriction
00413 );
00414
00418 virtual void OnMiscellaneousCommand(
00419 const H245_MiscellaneousCommand_type & type
00420 );
00421
00425 virtual void OnMiscellaneousIndication(
00426 const H245_MiscellaneousIndication_type & type
00427 );
00428
00429 Direction GetDirection() const { return direction; }
00430
00431 const OpalMediaFormat & GetMediaFormat() const { return mediaFormat; }
00432
00440 virtual BOOL AttachChannel(
00441 PChannel * channel,
00442 BOOL autoDelete = TRUE
00443 );
00444
00449 virtual PChannel * SwapChannel(
00450 PChannel * newChannel,
00451 BOOL autoDelete = TRUE
00452 );
00453
00456 virtual BOOL CloseRawDataChannel();
00457
00461 PChannel *GetRawDataChannel()
00462 { return rawDataChannel; }
00463
00470 virtual BOOL IsRawDataChannelNative() const;
00471
00474 BOOL ReadRaw(
00475 void * data,
00476 PINDEX size,
00477 PINDEX & length
00478 );
00479
00482 BOOL WriteRaw(
00483 void * data,
00484 PINDEX length
00485 );
00486
00493 BOOL AttachLogicalChannel(H323Channel *channel);
00494
00495 class FilterInfo : public PObject {
00496 PCLASSINFO(FilterInfo, PObject);
00497 public:
00498 FilterInfo(H323Codec & c, void * b, PINDEX s, PINDEX l)
00499 : codec(c), buffer(b), bufferSize(s), bufferLength(l) { }
00500
00501 H323Codec & codec;
00502 void * buffer;
00503 PINDEX bufferSize;
00504 PINDEX bufferLength;
00505 };
00506
00528 void AddFilter(
00529 const PNotifier & notifier
00530 );
00531
00532 protected:
00533 Direction direction;
00534 OpalMediaFormat mediaFormat;
00535
00536 H323Channel * logicalChannel;
00537
00538 PChannel * rawDataChannel;
00539 BOOL deleteChannel;
00540 PMutex rawChannelMutex;
00541
00542 PINDEX lastSequenceNumber;
00543
00544 PLIST(FilterList, PNotifier);
00545 FilterList filters;
00546 };
00547
00548 #ifndef NO_H323_AUDIO_CODECS
00549
00550
00557 class H323AudioCodec : public H323Codec
00558 {
00559 PCLASSINFO(H323AudioCodec, H323Codec);
00560
00561 public:
00567 H323AudioCodec(
00568 const char * mediaFormat,
00569 Direction direction
00570 );
00571
00572 ~H323AudioCodec();
00573
00582 virtual BOOL Open(
00583 H323Connection & connection
00584 );
00585
00593 virtual void Close();
00594
00597 virtual unsigned GetFrameRate() const;
00598
00599 enum SilenceDetectionMode {
00600 NoSilenceDetection,
00601 FixedSilenceDetection,
00602 AdaptiveSilenceDetection
00603 };
00604
00608 void SetSilenceDetectionMode(
00609 SilenceDetectionMode mode,
00610 unsigned threshold = 0,
00611 unsigned signalDeadband = 80,
00612 unsigned silenceDeadband = 3200,
00613 unsigned adaptivePeriod = 4800
00614 );
00615
00624 SilenceDetectionMode GetSilenceDetectionMode(
00625 BOOL * isInTalkBurst = NULL,
00626 unsigned * currentThreshold = NULL
00627 ) const;
00628
00629
00636 virtual void SetTxQualityLevel(int ) {}
00637
00641 virtual int GetTxQualityLevel(int ) { return 1; }
00642
00649 virtual BOOL DetectSilence();
00650
00658 virtual unsigned GetAverageSignalLevel();
00659
00660 protected:
00661 unsigned samplesPerFrame;
00662
00663 SilenceDetectionMode silenceDetectMode;
00664
00665 unsigned signalDeadbandFrames;
00666 unsigned silenceDeadbandFrames;
00667 unsigned adaptiveThresholdFrames;
00668
00669 BOOL inTalkBurst;
00670 unsigned framesReceived;
00671 unsigned levelThreshold;
00672 unsigned signalMinimum;
00673 unsigned silenceMaximum;
00674 unsigned signalFramesReceived;
00675 unsigned silenceFramesReceived;
00676 };
00677
00678
00687 class H323FramedAudioCodec : public H323AudioCodec
00688 {
00689 PCLASSINFO(H323FramedAudioCodec, H323AudioCodec);
00690
00691 public:
00697 H323FramedAudioCodec(
00698 const char * mediaFormat,
00699 Direction direction
00700 );
00701
00719 virtual BOOL Read(
00720 BYTE * buffer,
00721 unsigned & length,
00722 RTP_DataFrame & rtpFrame
00723 );
00724
00737 virtual BOOL Write(
00738 const BYTE * buffer,
00739 unsigned length,
00740 const RTP_DataFrame & rtpFrame,
00741 unsigned & written
00742 );
00743
00744
00749 virtual unsigned GetAverageSignalLevel();
00750
00751
00757 virtual BOOL EncodeFrame(
00758 BYTE * buffer,
00759 unsigned & length
00760 ) = 0;
00761
00766 virtual BOOL DecodeFrame(
00767 const BYTE * buffer,
00768 unsigned length,
00769 unsigned & written,
00770 unsigned & bytesOutput
00771 );
00772 virtual BOOL DecodeFrame(
00773 const BYTE * buffer,
00774 unsigned length,
00775 unsigned & written
00776 );
00777
00782 virtual void DecodeSilenceFrame(
00783 void * buffer,
00784 unsigned length
00785 )
00786 { memset(buffer, 0, length); }
00787
00788 protected:
00789 PShortArray sampleBuffer;
00790 unsigned bytesPerFrame;
00791 };
00792
00793
00802 class H323StreamedAudioCodec : public H323FramedAudioCodec
00803 {
00804 PCLASSINFO(H323StreamedAudioCodec, H323FramedAudioCodec);
00805
00806 public:
00812 H323StreamedAudioCodec(
00813 const char * mediaFormat,
00814 Direction direction,
00815 unsigned samplesPerFrame,
00816 unsigned bits
00817 );
00818
00824 virtual BOOL EncodeFrame(
00825 BYTE * buffer,
00826 unsigned & length
00827 );
00828
00834 virtual BOOL DecodeFrame(
00835 const BYTE * buffer,
00836 unsigned length,
00837 unsigned & written,
00838 unsigned & samples
00839 );
00840
00843 virtual int Encode(short sample) const = 0;
00844
00847 virtual short Decode(int sample) const = 0;
00848
00849 protected:
00850 unsigned bitsPerSample;
00851 };
00852
00853 #endif // NO_H323_AUDIO_CODECS
00854
00855
00856 #ifndef NO_H323_VIDEO
00857
00864 class H323VideoCodec : public H323Codec
00865 {
00866 PCLASSINFO(H323VideoCodec, H323Codec);
00867
00868 public:
00874 H323VideoCodec(
00875 const char * mediaFormat,
00876 Direction direction
00877 );
00878
00879 ~H323VideoCodec();
00880
00889 virtual BOOL Open(
00890 H323Connection & connection
00891 );
00892
00900 virtual void Close();
00901
00902
00906 virtual void OnMiscellaneousCommand(
00907 const H245_MiscellaneousCommand_type & type
00908 );
00909
00913 virtual void OnMiscellaneousIndication(
00914 const H245_MiscellaneousIndication_type & type
00915 );
00916
00917
00918
00919
00920
00921
00922
00923
00924
00928 virtual void OnFreezePicture();
00929
00933 virtual void OnFastUpdatePicture();
00934
00938 virtual void OnFastUpdateGOB(unsigned firstGOB, unsigned numberOfGOBs);
00939
00943 virtual void OnFastUpdateMB(int firstGOB, int firstMB, unsigned numberOfMBs);
00944
00948 virtual void OnVideoIndicateReadyToActivate();
00949
00953 virtual void OnVideoTemporalSpatialTradeOffCommand(int newQuality);
00954
00958 virtual void OnVideoTemporalSpatialTradeOffIndication(int newQuality);
00959
00963 virtual void OnVideoNotDecodedMBs(
00964 unsigned firstMB,
00965 unsigned numberOfMBs,
00966 unsigned temporalReference
00967 );
00968
00972 virtual void OnLostPartialPicture();
00973
00977 virtual void OnLostPicture();
00978
00981 int GetWidth() const { return frameWidth; }
00982
00985 int GetHeight() const { return frameHeight; }
00986
00989 virtual void SetTxQualityLevel(int qlevel) {videoQuality = qlevel; }
00990
00994 virtual void SetTxMinQuality(int qlevel) {videoQMin = qlevel; }
00995
00999 virtual void SetTxMaxQuality(int qlevel) {videoQMax = qlevel; }
01000
01003 virtual void SetBackgroundFill(int idle) {fillLevel= idle; }
01004
01005 enum BitRateModeBits {
01006 None = 0x00,
01007 DynamicVideoQuality = 0x01,
01008 AdaptivePacketDelay = 0x02
01009 };
01010
01013 unsigned GetVideoMode(void) {return videoBitRateControlModes;}
01014
01018 unsigned SetVideoMode(unsigned mode) {return videoBitRateControlModes = mode;}
01019
01024 virtual BOOL SetMaxBitRate(
01025 unsigned bitRate
01026 );
01027
01036 virtual BOOL SetTargetFrameTimeMs(
01037 unsigned ms
01038 );
01039
01044 void SendMiscCommand(unsigned command);
01045
01049 virtual int GetFrameNum() { return frameNum; }
01050
01051
01052 protected:
01053
01054 int frameWidth;
01055 int frameHeight;
01056 int fillLevel;
01057
01058
01059 unsigned videoBitRateControlModes;
01060
01061 int bitRateHighLimit;
01062 unsigned oldLength;
01063 PTimeInterval oldTime;
01064 PTimeInterval newTime;
01065
01066 int targetFrameTimeMs;
01067 int frameBytes;
01068 int sumFrameTimeMs, sumAdjFrameTimeMs, sumFrameBytes;
01069 int videoQMax, videoQMin;
01070 int videoQuality;
01071 PTimeInterval frameStartTime;
01072 PTimeInterval grabInterval;
01073
01074 int frameNum, packetNum, oldPacketNum;
01075 int framesPerSec;
01076
01077 PMutex videoHandlerActive;
01078 };
01079
01080 #endif // NO_H323_VIDEO
01081
01082 #ifndef NO_H323_AUDIO_CODECS
01083
01085
01086
01089 class H323_ALawCodec : public H323StreamedAudioCodec
01090 {
01091 PCLASSINFO(H323_ALawCodec, H323StreamedAudioCodec)
01092
01093 public:
01098 H323_ALawCodec(
01099 Direction direction,
01100 BOOL at56kbps,
01101 unsigned frameSize
01102 );
01104
01105 virtual int Encode(short sample) const { return EncodeSample(sample); }
01106 virtual short Decode(int sample) const { return DecodeSample(sample); }
01107
01108 static int EncodeSample(short sample);
01109 static short DecodeSample(int sample);
01110
01111 protected:
01112 BOOL sevenBit;
01113 };
01114
01115
01118 class H323_muLawCodec : public H323StreamedAudioCodec
01119 {
01120 PCLASSINFO(H323_muLawCodec, H323StreamedAudioCodec)
01121
01122 public:
01127 H323_muLawCodec(
01128 Direction direction,
01129 BOOL at56kbps,
01130 unsigned frameSize
01131 );
01133
01134 virtual int Encode(short sample) const { return EncodeSample(sample); }
01135 virtual short Decode(int sample) const { return DecodeSample(sample); }
01136
01137 static int EncodeSample(short sample);
01138 static short DecodeSample(int sample);
01139
01140 protected:
01141 BOOL sevenBit;
01142 };
01143
01144 #endif // NO_H323_AUDIO_CODECS
01145
01146
01147 #endif // __CODECS_H
01148
01149