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
#ifndef __CODECS_H
00279
#define __CODECS_H
00280
00281
#ifdef P_USE_PRAGMA
00282
#pragma interface
00283
#endif
00284
00285
00286
#include <mediafmt.h>
00287
#include <rtp.h>
00288
#include <channels.h>
00289
#include "openh323buildopts.h"
00290
00291
00292
00293
00294
00295
00296
00297
class H245_MiscellaneousCommand_type;
00298
class H245_MiscellaneousIndication_type;
00299
class H323Connection;
00300
00301
00302
00304
00312 class H323Codec :
public PObject
00313 {
00314 PCLASSINFO(
H323Codec, PObject);
00315
00316
public:
00317 enum Direction {
00318
Encoder,
00319
Decoder
00320 };
00321
00322
H323Codec(
00323
const char * mediaFormat,
00324 Direction direction
00325 );
00326
00327
00340
virtual BOOL Open(
00341
H323Connection & connection
00342 );
00343
00346
virtual void Close() = 0;
00347
00365
virtual BOOL Read(
00366 BYTE * buffer,
00367
unsigned & length,
00368
RTP_DataFrame & rtpFrame
00369 ) = 0;
00370
00382
virtual BOOL Write(
00383
const BYTE * buffer,
00384
unsigned length,
00385
const RTP_DataFrame & frame,
00386
unsigned & written
00387 ) = 0;
00388
00391
virtual unsigned GetFrameRate() const;
00392
00396 virtual
void OnFlowControl(
00397
long bitRateRestriction
00398 );
00399
00403 virtual
void OnMiscellaneousCommand(
00404 const
H245_MiscellaneousCommand_type & type
00405 );
00406
00410 virtual
void OnMiscellaneousIndication(
00411 const
H245_MiscellaneousIndication_type & type
00412 );
00413
00414 Direction GetDirection()
const {
return direction; }
00415
00416 const OpalMediaFormat &
GetMediaFormat()
const {
return mediaFormat; }
00417
00425
virtual BOOL AttachChannel(
00426 PChannel * channel,
00427 BOOL autoDelete = TRUE
00428 );
00429
00434
virtual PChannel * SwapChannel(
00435 PChannel * newChannel,
00436 BOOL autoDelete = TRUE
00437 );
00438
00441
virtual BOOL
CloseRawDataChannel();
00442
00446 PChannel *
GetRawDataChannel()
00447 {
return rawDataChannel; }
00448
00455
virtual BOOL
IsRawDataChannelNative() const;
00456
00459 BOOL ReadRaw(
00460
void * data,
00461 PINDEX size,
00462 PINDEX & length
00463 );
00464
00467 BOOL WriteRaw(
00468
void * data,
00469 PINDEX length
00470 );
00471
00478 BOOL AttachLogicalChannel(
H323Channel *channel);
00479
00480 class
FilterInfo : public PObject {
00481 PCLASSINFO(
FilterInfo, PObject);
00482
public:
00483 FilterInfo(
H323Codec & c,
void * b, PINDEX s, PINDEX l)
00484 : codec(c), buffer(b), bufferSize(s), bufferLength(l) { }
00485
00486 H323Codec & codec;
00487 void * buffer;
00488 PINDEX bufferSize;
00489 PINDEX bufferLength;
00490 };
00491
00513
void AddFilter(
00514
const PNotifier & notifier
00515 );
00516
00517
protected:
00518 Direction direction;
00519 OpalMediaFormat mediaFormat;
00520
00521 H323Channel *
logicalChannel;
00522
00523 PChannel *
rawDataChannel;
00524 BOOL
deleteChannel;
00525 PMutex
rawChannelMutex;
00526
00527 PINDEX
lastSequenceNumber;
00528
00529
PLIST(FilterList, PNotifier);
00530 FilterList
filters;
00531 };
00532
00533
00540 class H323AudioCodec :
public H323Codec
00541 {
00542 PCLASSINFO(
H323AudioCodec,
H323Codec);
00543
00544
public:
00550
H323AudioCodec(
00551
const char * mediaFormat,
00552 Direction direction
00553 );
00554
00555
~H323AudioCodec();
00556
00565
virtual BOOL
Open(
00566
H323Connection & connection
00567 );
00568
00576
virtual void Close();
00577
00580
virtual unsigned GetFrameRate()
const;
00581
00582 enum SilenceDetectionMode {
00583
NoSilenceDetection,
00584
FixedSilenceDetection,
00585
AdaptiveSilenceDetection
00586 };
00587
00591
void SetSilenceDetectionMode(
00592 SilenceDetectionMode mode,
00593
unsigned threshold = 0,
00594
unsigned signalDeadband = 80,
00595
unsigned silenceDeadband = 3200,
00596
unsigned adaptivePeriod = 4800
00597 );
00598
00607 SilenceDetectionMode GetSilenceDetectionMode(
00608 BOOL * isInTalkBurst = NULL,
00609
unsigned * currentThreshold = NULL
00610 )
const;
00611
00618
virtual BOOL
DetectSilence();
00619
00627
virtual unsigned GetAverageSignalLevel();
00628
00629
protected:
00630 unsigned samplesPerFrame;
00631
00632 SilenceDetectionMode silenceDetectMode;
00633
00634 unsigned signalDeadbandFrames;
00635 unsigned silenceDeadbandFrames;
00636 unsigned adaptiveThresholdFrames;
00637
00638 BOOL
inTalkBurst;
00639 unsigned framesReceived;
00640 unsigned levelThreshold;
00641 unsigned signalMinimum;
00642 unsigned silenceMaximum;
00643 unsigned signalFramesReceived;
00644 unsigned silenceFramesReceived;
00645 };
00646
00647
00656 class H323FramedAudioCodec :
public H323AudioCodec
00657 {
00658 PCLASSINFO(
H323FramedAudioCodec,
H323AudioCodec);
00659
00660
public:
00666
H323FramedAudioCodec(
00667
const char * mediaFormat,
00668 Direction direction
00669 );
00670
00688
virtual BOOL
Read(
00689 BYTE * buffer,
00690
unsigned & length,
00691
RTP_DataFrame & rtpFrame
00692 );
00693
00706
virtual BOOL
Write(
00707
const BYTE * buffer,
00708
unsigned length,
00709
const RTP_DataFrame & rtpFrame,
00710
unsigned & written
00711 );
00712
00713
00718
virtual unsigned GetAverageSignalLevel();
00719
00720
00726
virtual BOOL
EncodeFrame(
00727 BYTE * buffer,
00728
unsigned & length
00729 ) = 0;
00730
00735
virtual BOOL
DecodeFrame(
00736
const BYTE * buffer,
00737
unsigned length,
00738
unsigned & written,
00739
unsigned & bytesOutput
00740 );
00741
virtual BOOL DecodeFrame(
00742
const BYTE * buffer,
00743
unsigned length,
00744
unsigned & written
00745 );
00746
00751 virtual void DecodeSilenceFrame(
00752
void * buffer,
00753
unsigned length
00754 )
00755 { memset(buffer, 0, length); }
00756
00757
protected:
00758 PShortArray
sampleBuffer;
00759 unsigned bytesPerFrame;
00760 };
00761
00762
00771 class H323StreamedAudioCodec :
public H323FramedAudioCodec
00772 {
00773 PCLASSINFO(
H323StreamedAudioCodec,
H323FramedAudioCodec);
00774
00775
public:
00781
H323StreamedAudioCodec(
00782
const char * mediaFormat,
00783 Direction direction,
00784
unsigned samplesPerFrame,
00785
unsigned bits
00786 );
00787
00793
virtual BOOL
EncodeFrame(
00794 BYTE * buffer,
00795
unsigned & length
00796 );
00797
00803
virtual BOOL
DecodeFrame(
00804
const BYTE * buffer,
00805
unsigned length,
00806
unsigned & written,
00807
unsigned & samples
00808 );
00809
00812
virtual int Encode(
short sample)
const = 0;
00813
00816
virtual short Decode(
int sample)
const = 0;
00817
00818
protected:
00819 unsigned bitsPerSample;
00820 };
00821
00822
00823
#ifndef NO_H323_VIDEO
00824
00831 class H323VideoCodec :
public H323Codec
00832 {
00833 PCLASSINFO(
H323VideoCodec,
H323Codec);
00834
00835
public:
00841
H323VideoCodec(
00842
const char * mediaFormat,
00843 Direction direction
00844 );
00845
00846
~H323VideoCodec();
00847
00856
virtual BOOL
Open(
00857
H323Connection & connection
00858 );
00859
00867
virtual void Close();
00868
00869
00873
virtual void OnMiscellaneousCommand(
00874
const H245_MiscellaneousCommand_type & type
00875 );
00876
00880
virtual void OnMiscellaneousIndication(
00881
const H245_MiscellaneousIndication_type & type
00882 );
00883
00884
00885
00886
00887
00888
00889
00890
00891
00895
virtual void OnFreezePicture();
00896
00900
virtual void OnFastUpdatePicture();
00901
00905
virtual void OnFastUpdateGOB(
unsigned firstGOB,
unsigned numberOfGOBs);
00906
00910
virtual void OnFastUpdateMB(
int firstGOB,
int firstMB,
unsigned numberOfMBs);
00911
00915
virtual void OnVideoIndicateReadyToActivate();
00916
00920
virtual void OnVideoTemporalSpatialTradeOffCommand(
int newQuality);
00921
00925
virtual void OnVideoTemporalSpatialTradeOffIndication(
int newQuality);
00926
00930
virtual void OnVideoNotDecodedMBs(
00931
unsigned firstMB,
00932
unsigned numberOfMBs,
00933
unsigned temporalReference
00934 );
00935
00939
virtual void OnLostPartialPicture();
00940
00944
virtual void OnLostPicture();
00945
00948 int GetWidth()
const {
return frameWidth; }
00949
00952 int GetHeight()
const {
return frameHeight; }
00953
00956 virtual void SetTxQualityLevel(
int qlevel) {
videoQuality = qlevel; }
00957
00961 virtual void SetTxMinQuality(
int qlevel) {
videoQMin = qlevel; }
00962
00966 virtual void SetTxMaxQuality(
int qlevel) {
videoQMax = qlevel; }
00967
00970 virtual void SetBackgroundFill(
int idle) {
fillLevel= idle; }
00971
00972 enum BitRateModeBits {
00973
None = 0x00,
00974
DynamicVideoQuality = 0x01,
00975
AdaptivePacketDelay = 0x02
00976 };
00977
00980 unsigned GetVideoMode(
void) {
return videoBitRateControlModes;}
00981
00985 unsigned SetVideoMode(
unsigned mode) {
return videoBitRateControlModes = mode;}
00986
00991
virtual BOOL SetMaxBitRate(
00992
unsigned bitRate
00993 );
00994
01003
virtual BOOL SetTargetFrameTimeMs(
01004
unsigned ms
01005 );
01006
01011
void SendMiscCommand(
unsigned command);
01012
01016 virtual int GetFrameNum() {
return frameNum; }
01017
01018
01019
protected:
01020
01021 int frameWidth;
01022 int frameHeight;
01023 int fillLevel;
01024
01025
01026 unsigned videoBitRateControlModes;
01027
01028 int bitRateHighLimit;
01029 unsigned oldLength;
01030 PTimeInterval
oldTime;
01031 PTimeInterval
newTime;
01032
01033 int targetFrameTimeMs;
01034 int frameBytes;
01035 int sumFrameTimeMs,
sumAdjFrameTimeMs,
sumFrameBytes;
01036 int videoQMax,
videoQMin;
01037 int videoQuality;
01038 PTimeInterval
frameStartTime;
01039 PTimeInterval
grabInterval;
01040
01041 int frameNum,
packetNum,
oldPacketNum;
01042 int framesPerSec;
01043
01044 PMutex
videoHandlerActive;
01045 };
01046
01047
#endif // NO_H323_VIDEO
01048
01049
01051
01052
01055 class H323_ALawCodec :
public H323StreamedAudioCodec
01056 {
01057 PCLASSINFO(
H323_ALawCodec,
H323StreamedAudioCodec)
01058
01059
public:
01064
H323_ALawCodec(
01065 Direction direction,
01066 BOOL at56kbps,
01067
unsigned frameSize
01068 );
01070
01071 virtual int Encode(
short sample)
const {
return EncodeSample(sample); }
01072 virtual short Decode(
int sample)
const {
return DecodeSample(sample); }
01073
01074
static int EncodeSample(
short sample);
01075
static short DecodeSample(
int sample);
01076
01077
protected:
01078 BOOL
sevenBit;
01079 };
01080
01081
01084 class H323_muLawCodec :
public H323StreamedAudioCodec
01085 {
01086 PCLASSINFO(
H323_muLawCodec,
H323StreamedAudioCodec)
01087
01088
public:
01093
H323_muLawCodec(
01094 Direction direction,
01095 BOOL at56kbps,
01096
unsigned frameSize
01097 );
01099
01100 virtual int Encode(
short sample)
const {
return EncodeSample(sample); }
01101 virtual short Decode(
int sample)
const {
return DecodeSample(sample); }
01102
01103
static int EncodeSample(
short sample);
01104
static short DecodeSample(
int sample);
01105
01106
protected:
01107 BOOL
sevenBit;
01108 };
01109
01110
01111
#endif // __CODECS_H
01112
01113