📄 codecs.h
字号:
levelThreshold, signalDeadbandFrames and silenceDeadbandFrames member variables. */ BOOL DetectSilence(); /**Get the average signal level in the audio stream. This is called from within DetectSilence() to calculate the average signal level since the last call to DetectSilence(). The default behaviour returns UINT_MAX which disables the silence detection algorithm. */ virtual unsigned GetAverageSignalLevel(); protected: unsigned samplesPerFrame; PChannel * rawDataChannel; BOOL deleteChannel; SilenceDetectionMode silenceDetectMode; unsigned signalDeadbandFrames; // Frames of signal before talk burst starts unsigned silenceDeadbandFrames; // Frames of silence before talk burst ends unsigned adaptiveThresholdFrames; // Frames to min/max over for adaptive threshold BOOL inTalkBurst; // Currently sending RTP data unsigned framesReceived; // Signal/Silence frames received so far. unsigned levelThreshold; // Threshold level for silence/signal unsigned signalMinimum; // Minimum of frames above threshold unsigned silenceMaximum; // Maximum of frames below threshold unsigned signalFramesReceived; // Frames of signal received unsigned silenceFramesReceived; // Frames of silence received};/**This class defines a codec class that will use the standard platform PCM output device, and the encoding/decoding has fixed blocks. That is each input block of n samples is encoded to exactly the same sized compressed data, eg G.711, GSM etc. An application may create a descendent off this class and override functions as required for descibing a specific codec. */class H323FramedAudioCodec : public H323AudioCodec{ PCLASSINFO(H323FramedAudioCodec, H323AudioCodec); public: /** Create a new audio codec. This opens the standard PCM audio output device, for input and output and allows descendent codec classes to do audio I/O after decoding/encoding. */ H323FramedAudioCodec( Direction direction, /// Direction in which this instance runs unsigned samplesPerFrame, /// Number of samples in a frame unsigned bytesPerFrame /// Number of bytes in a frame ); /**Encode the data from the appropriate device. This will encode a frame of data for transmission. The exact size and description of the data placed in the buffer is codec dependent but should be less than H323Capability::GetTxFramesInPacket() * H323Capability::GetMaxFrameSize() in length. The length parameter is filled with the actual length of the encoded data, often this will be the same as the size parameter. This function is called every GetFrameRate() timestamp units, so MUST take less than (or equal to) that amount of time to complete! Note that a returned length of zero indicates that time has passed but there is no data encoded. This is typically used for silence detection in an audio codec. */ virtual BOOL Read( BYTE * buffer, /// Buffer of encoded data unsigned & length, /// Actual length of encoded data buffer RTP_DataFrame & rtpFrame /// RTP data frame ); /**Decode the data and output it to appropriate device. This will decode a single frame of received data. The exact size and description of the data required in the buffer is codec dependent but should be less than H323Capability::GetRxFramesInPacket() * H323Capability::GetMaxFrameSize() in length. It is expected this function anunciates the data. That is, for example with audio data, the sound is output on a speaker. This function is called every GetFrameRate() timestamp units, so MUST take less than that amount of time to complete! */ virtual BOOL Write( const BYTE * buffer, /// Buffer of encoded data unsigned length, /// Length of encoded data buffer const RTP_DataFrame & rtpFrame, /// RTP data frame unsigned & written /// Number of bytes used from data buffer ); /**Get the bandwidth used by the channel in 100's of bits/sec. The default behaviour calculates the bandwidth used from the bytesPerFrame and frame rate parameters. */ virtual unsigned GetBandwidth() const; /**Get the average signal level in the audio stream. This is called from within DetectSilence() to calculate the average signal level since the last call to DetectSilence(). */ virtual unsigned GetAverageSignalLevel(); /**Encode a sample block into the buffer specified. The samples have been read and are waiting in the readBuffer member variable. it is expected this function will encode exactly bytesPerFrame bytes. */ virtual BOOL EncodeFrame( BYTE * buffer, /// Buffer into which encoded bytes are placed unsigned & length /// Actual length of encoded data buffer ) = 0; /**Decode a sample block from the buffer specified. The samples must be placed into the writeBuffer member variable. It is expected that exactly samplesPerFrame samples is decoded. */ virtual BOOL DecodeFrame( const BYTE * buffer, /// Buffer from which encoded data is found unsigned length, /// Length of encoded data buffer unsigned & written /// Number of bytes used from data buffer ) = 0; protected: PShortArray sampleBuffer; unsigned bytesPerFrame;};/**This class defines a codec class that will use the standard platform PCM output device, and the encoding/decoding is streamed. That is each input 16 bit PCM sample is encoded to 8 bits or less of encoded data and no blocking of PCM data is required, eg G.711, G.721 etc. An application may create a descendent off this class and override functions as required for descibing a specific codec. */class H323StreamedAudioCodec : public H323FramedAudioCodec{ PCLASSINFO(H323StreamedAudioCodec, H323FramedAudioCodec); public: /** Create a new audio codec. This opens the standard PCM audio output device, for input and output and allows descendent codec classes to do audio I/O after decoding/encoding. */ H323StreamedAudioCodec( Direction direction, /// Direction in which this instance runs unsigned samplesPerFrame, /// Number of samples in a frame unsigned bits /// Bits per sample ); /**Encode a sample block into the buffer specified. The samples have been read and are waiting in the readBuffer member variable. it is expected this function will encode exactly encodedBlockSize bytes. */ virtual BOOL EncodeFrame( BYTE * buffer, /// Buffer into which encoded bytes are placed unsigned & length /// Actual length of encoded data buffer ); /**Decode a sample block from the buffer specified. The samples must be placed into the writeBuffer member variable. It is expected that no more than frameSamples is decoded. The return value is the number of samples decoded. Zero indicates an error. */ virtual BOOL DecodeFrame( const BYTE * buffer, /// Buffer from which encoded data is found unsigned length, /// Length of encoded data buffer unsigned & written /// Number of bytes used from data buffer ); /**Encode a single sample value. */ virtual int Encode(short sample) const = 0; /**Decode a single sample value. */ virtual short Decode(int sample) const = 0; protected: unsigned bitsPerSample;};/**This class defines a codec class that will use the standard platform image output device. An application may create a descendent off this class and override functions as required for descibing a specific codec. */class H323VideoCodec : public H323Codec{ PCLASSINFO(H323VideoCodec, H323Codec); public: /** Create a new video codec. This opens the standard image output device, for input and output and allows descendent codec classes to do video I/O after decoding/encoding. */ H323VideoCodec( Direction direction /// Direction in which this instance runs ); ~H323VideoCodec(); /**Open the codec. This will open the codec for encoding or decoding. This is primarily used to delay allocation of resources until the last minute. The default behaviour calls the H323EndPoint::OpenVideoDevice() function and assigns the result of that function to the raw data channel in the H323Codec class. */ virtual BOOL Open( H323Connection & connection /// Connection between the endpoints ); /**Close down the codec. This will close the codec breaking any block on the Read() or Write() functions. The default behaviour will close the rawDataChannel if it is not NULL and thene delete it if delteChannel is TRUE. */ virtual void Close(); /**Get the number of RTP timestamp units per millisecond. */ virtual unsigned GetTimeUnits() const; /**Indicate whether the codec requires jitter buffering. Default behaviour returns FALSE, video codecs no NOT require jitter buffering. */ virtual BOOL NeedsJitterBuffer() const; /**Process a miscellaneous command on the logical channel. The default behaviour does nothing. */ virtual void OnMiscellaneousCommand( const H245_MiscellaneousCommand_type & type /// Command to process ); /**Process a miscellaneous indication on the logical channel. The default behaviour does nothing. */ virtual void OnMiscellaneousIndication( const H245_MiscellaneousIndication_type & type /// Indication to process ); /**Attach the raw data channel for use by codec. Note the channel provided will be deleted on destruction of the codec. */ virtual BOOL AttachDevice( H323VideoDevice * device, /// Device to read/write data BOOL autoDelete = TRUE /// Device is to be automatically deleted ); /**Process a FreezePicture command from remote endpoint. The default behaviour does nothing. */ virtual void OnFreezePicture(); /**Process a FastUpdatePicture command from remote endpoint. The default behaviour does nothing. */ virtual void OnFastUpdatePicture(); /**Process a FastUpdateGOB command from remote endpoint. The default behaviour does nothing. */ virtual void OnFastUpdateGOB(unsigned firstGOB, unsigned numberOfGOBs); /**Process a FastUpdateMB command from remote endpoint. The default behaviour does nothing. */ virtual void OnFastUpdateMB(int firstGOB, int firstMB, unsigned numberOfMBs); /**Process a OnVideoIndicateReadyToActivate indication from remote endpoint. The default behaviour does nothing. */ virtual void OnVideoIndicateReadyToActivate(); /**Process a OnVideoTemporalSpatialTradeOff indication from remote endpoint. The default behaviour does nothing. */ virtual void OnVideoTemporalSpatialTradeOff(); /**Process a OnVideoNotDecodedMBs indication from remote endpoint. The default behaviour does nothing. */ virtual void OnVideoNotDecodedMBs(unsigned firstMB, unsigned numberOfMBs, unsigned temporalReference); /** Get width of video */ int GetWidth() const { return width; } /** Get height of video */ int GetHeight() const { return height; } /** Set video input */ virtual void SetVideoInput(int input) { videoInput = input; } /** Get video input */ int GetVideoInput() const { return videoInput; } /** Set video format */ virtual void SetVideoFormat(BOOL isPal) { videoIsPal = isPal; } /** Get video format */ BOOL GetVideoFormat() const { return videoIsPal; } protected: H323VideoDevice * rawDevice; BOOL deleteDevice; int width; int height; int videoInput; BOOL videoIsPal;};///////////////////////////////////////////////////////////////////////////////// The simplest codec is the G.711 PCM codec./**This class is a G711 ALaw codec. */class H323_ALawCodec : public H323StreamedAudioCodec{ PCLASSINFO(H323_ALawCodec, H323StreamedAudioCodec) public: /**@name Construction */ //@{ /**Create a new G.711 codec for ALaw. */ H323_ALawCodec( Direction direction, /// Direction in which this instance runs BOOL at56kbps, /// Encoding bit rate. unsigned frameSize /// Size of frame in bytes ); //@} virtual int Encode(short sample) const; virtual short Decode(int sample) const; protected: BOOL sevenBit;};/**This class is a G711 uLaw codec. */class H323_muLawCodec : public H323StreamedAudioCodec{ PCLASSINFO(H323_muLawCodec, H323StreamedAudioCodec) public: /**@name Construction */ //@{ /**Create a new G.711 codec for muLaw. */ H323_muLawCodec( Direction direction, /// Direction in which this instance runs BOOL at56kbps, /// Encoding bit rate. unsigned frameSize /// Size of frame in bytes ); //@} virtual int Encode(short sample) const; virtual short Decode(int sample) const; protected: BOOL sevenBit;};#endif // __CODECS_H/////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -