Refactored ViEEncoder.

Style changes + QT Metrics class from h-file to cc-file, type changes will be in another CL.

Review URL: http://webrtc-codereview.appspot.com/303001

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1078 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org 2011-12-01 17:02:23 +00:00
parent 5f4f69ac57
commit 84d17838ac
2 changed files with 866 additions and 1136 deletions

File diff suppressed because it is too large Load Diff

View File

@ -8,181 +8,167 @@
* be found in the AUTHORS file in the root of the source tree.
*/
/*
* vie_encoder.h
*/
#ifndef WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_
#define WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_
#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCODER_H_
#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCODER_H_
#include "vie_defines.h"
#include "typedefs.h"
#include "vie_frame_provider_base.h"
#include "vie_file_recorder.h"
#include "common_types.h"
#include "rtp_rtcp_defines.h"
#include "typedefs.h"
#include "video_coding_defines.h"
#include "video_processing.h"
#include "common_types.h"
#include "vie_defines.h"
#include "vie_file_recorder.h"
#include "vie_frame_provider_base.h"
namespace webrtc {
class CriticalSectionWrapper;
class ProcessThread;
class QMTestVideoSettingsCallback;
class RtpRtcp;
class ViEEffectFilter;
class VideoCodingModule;
class ViEEffectFilter;
class ViEEncoderObserver;
class ViEEncoder: public ViEFrameCallback, // New frame delivery
public RtpVideoFeedback, // Feedback from RTP module
public RtcpFeedback, // RTP/RTCP Module
public VCMPacketizationCallback, // Callback from VCM
public VCMProtectionCallback, // Callback from VCM
public VCMSendStatisticsCallback // Callback from VCM
{
public:
ViEEncoder(WebRtc_Word32 engineId, WebRtc_Word32 channelId,
WebRtc_UWord32 numberOfCores,
ProcessThread& moduleProcessThread);
~ViEEncoder();
class ViEEncoder
: public RtpVideoFeedback,
public RtcpFeedback,
public VCMPacketizationCallback,
public VCMProtectionCallback,
public VCMSendStatisticsCallback,
public ViEFrameCallback {
public:
ViEEncoder(WebRtc_Word32 engine_id,
WebRtc_Word32 channel_id,
WebRtc_UWord32 number_of_cores,
ProcessThread& module_process_thread);
~ViEEncoder();
// Drops incoming packets
void Pause();
void Restart();
// Drops incoming packets before they get to the encoder.
void Pause();
void Restart();
WebRtc_Word32 DropDeltaAfterKey(bool enable);
WebRtc_Word32 DropDeltaAfterKey(bool enable);
// Codec settings
WebRtc_UWord8 NumberOfCodecs();
WebRtc_Word32 GetCodec(WebRtc_UWord8 listIndex, VideoCodec& videoCodec);
WebRtc_Word32 RegisterExternalEncoder(VideoEncoder* encoder,
WebRtc_UWord8 plType);
WebRtc_Word32 DeRegisterExternalEncoder(WebRtc_UWord8 plType);
WebRtc_Word32 SetEncoder(const VideoCodec& videoCodec);
WebRtc_Word32 GetEncoder(VideoCodec& videoCodec);
// Codec settings.
WebRtc_UWord8 NumberOfCodecs();
WebRtc_Word32 GetCodec(WebRtc_UWord8 list_index, VideoCodec& video_codec);
WebRtc_Word32 RegisterExternalEncoder(VideoEncoder* encoder,
WebRtc_UWord8 pl_type);
WebRtc_Word32 DeRegisterExternalEncoder(WebRtc_UWord8 pl_type);
WebRtc_Word32 SetEncoder(const VideoCodec& video_codec);
WebRtc_Word32 GetEncoder(VideoCodec& video_codec);
WebRtc_Word32 GetCodecConfigParameters(
unsigned char configParameters[kConfigParameterSize],
unsigned char& configParametersSize);
WebRtc_Word32 GetCodecConfigParameters(
unsigned char config_parameters[kConfigParameterSize],
unsigned char& config_parameters_size);
// Scale or crop/pad image
WebRtc_Word32 ScaleInputImage(bool enable);
// Scale or crop/pad image.
WebRtc_Word32 ScaleInputImage(bool enable);
// RTP settings
RtpRtcp* SendRtpRtcpModule();
// RTP settings.
RtpRtcp* SendRtpRtcpModule();
// Implementing ViEFrameCallback
virtual void DeliverFrame(int id, VideoFrame& videoFrame, int numCSRCs = 0,
const WebRtc_UWord32 CSRC[kRtpCsrcSize] = NULL);
virtual void DelayChanged(int id, int frameDelay);
virtual int GetPreferedFrameSettings(int &width, int &height,
int &frameRate);
// Implementing ViEFrameCallback.
virtual void DeliverFrame(int id,
VideoFrame& video_frame,
int num_csrcs = 0,
const WebRtc_UWord32 CSRC[kRtpCsrcSize] = NULL);
virtual void DelayChanged(int id, int frame_delay);
virtual int GetPreferedFrameSettings(int& width,
int& height,
int& frame_rate);
virtual void ProviderDestroyed(int id) { return; }
virtual void ProviderDestroyed(int id) {
return;
}
WebRtc_Word32 EncodeFrame(VideoFrame& videoFrame);
WebRtc_Word32 SendKeyFrame();
WebRtc_Word32 SendCodecStatistics(WebRtc_UWord32& numKeyFrames,
WebRtc_UWord32& numDeltaFrames);
// Loss protection
WebRtc_Word32 UpdateProtectionMethod();
// Implements VCMPacketizationCallback
virtual WebRtc_Word32 SendData(
const FrameType frameType,
const WebRtc_UWord8 payloadType,
const WebRtc_UWord32 timeStamp,
const WebRtc_UWord8* payloadData,
const WebRtc_UWord32 payloadSize,
const RTPFragmentationHeader& fragmentationHeader,
const RTPVideoHeader* rtpVideoHdr);
// Implements VideoProtectionCallback
virtual WebRtc_Word32 ProtectionRequest(const WebRtc_UWord8 deltaFECRate,
const WebRtc_UWord8 keyFECRate,
const bool deltaUseUepProtection,
const bool keyUseUepProtection,
const bool nack);
WebRtc_Word32 EncodeFrame(VideoFrame& video_frame);
WebRtc_Word32 SendKeyFrame();
WebRtc_Word32 SendCodecStatistics(WebRtc_UWord32& num_key_frames,
WebRtc_UWord32& num_delta_frames);
// Loss protection.
WebRtc_Word32 UpdateProtectionMethod();
// Implements VideoSendStatisticsCallback
virtual WebRtc_Word32 SendStatistics(const WebRtc_UWord32 bitRate,
const WebRtc_UWord32 frameRate);
WebRtc_Word32 RegisterCodecObserver(ViEEncoderObserver* observer);
// Implements RtcpFeedback
virtual void OnSLIReceived(const WebRtc_Word32 id,
const WebRtc_UWord8 pictureId);
virtual void OnRPSIReceived(const WebRtc_Word32 id,
const WebRtc_UWord64 pictureId);
// Implements VCMPacketizationCallback.
virtual WebRtc_Word32 SendData(
const FrameType frame_type,
const WebRtc_UWord8 payload_type,
const WebRtc_UWord32 time_stamp,
const WebRtc_UWord8* payload_data,
const WebRtc_UWord32 payload_size,
const RTPFragmentationHeader& fragmentation_header,
const RTPVideoHeader* rtp_video_hdr);
// Implements RtpVideoFeedback
virtual void OnReceivedIntraFrameRequest(const WebRtc_Word32 id,
const FrameType type,
const WebRtc_UWord8 streamIdx);
// Implements VideoProtectionCallback.
virtual WebRtc_Word32 ProtectionRequest(const WebRtc_UWord8 delta_fecrate,
const WebRtc_UWord8 key_fecrate,
const bool delta_use_uep_protection,
const bool key_use_uep_protection,
const bool nack);
virtual void OnNetworkChanged(const WebRtc_Word32 id,
const WebRtc_UWord32 bitrateBps,
const WebRtc_UWord8 fractionLost,
const WebRtc_UWord16 roundTripTimeMs);
// Effect filter
WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effectFilter);
//Recording
ViEFileRecorder& GetOutgoingFileRecorder();
// Implements VideoSendStatisticsCallback.
virtual WebRtc_Word32 SendStatistics(const WebRtc_UWord32 bit_rate,
const WebRtc_UWord32 frame_rate);
WebRtc_Word32 RegisterCodecObserver(ViEEncoderObserver* observer);
private:
WebRtc_Word32 _engineId;
// Implements RtcpFeedback.
virtual void OnSLIReceived(const WebRtc_Word32 id,
const WebRtc_UWord8 picture_id);
virtual void OnRPSIReceived(const WebRtc_Word32 id,
const WebRtc_UWord64 picture_id);
class QMTestVideoSettingsCallback : public VCMQMSettingsCallback
{
public:
QMTestVideoSettingsCallback();
// update VPM with QM (quality modes: frame size & frame rate) settings
WebRtc_Word32 SetVideoQMSettings(const WebRtc_UWord32 frameRate,
const WebRtc_UWord32 width,
const WebRtc_UWord32 height);
// register VPM and VCM
void RegisterVPM(VideoProcessingModule* vpm);
void RegisterVCM(VideoCodingModule* vcm);
void SetNumOfCores(WebRtc_Word32 numOfCores)
{_numOfCores = numOfCores;};
void SetMaxPayloadLength(WebRtc_Word32 maxPayloadLength)
{_maxPayloadLength = maxPayloadLength;};
private:
VideoProcessingModule* _vpm;
VideoCodingModule* _vcm;
WebRtc_Word32 _numOfCores;
WebRtc_Word32 _maxPayloadLength;
};
// Implements RtpVideoFeedback.
virtual void OnReceivedIntraFrameRequest(const WebRtc_Word32 id,
const FrameType type,
const WebRtc_UWord8 stream_idx);
WebRtc_Word32 _channelId;
const WebRtc_UWord32 _numberOfCores;
virtual void OnNetworkChanged(const WebRtc_Word32 id,
const WebRtc_UWord32 bitrate_bps,
const WebRtc_UWord8 fraction_lost,
const WebRtc_UWord16 round_trip_time_ms);
VideoCodingModule& _vcm;
VideoProcessingModule& _vpm;
RtpRtcp& _defaultRtpRtcp;
CriticalSectionWrapper& _callbackCritsect;
CriticalSectionWrapper& _dataCritsect;
VideoCodec _sendCodec;
// Effect filter.
WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effect_filter);
bool _paused;
WebRtc_Word64 _timeLastIntraRequestMs[kMaxSimulcastStreams];
WebRtc_Word32 _channelsDroppingDeltaFrames;
bool _dropNextFrame;
//Loss protection
bool _fecEnabled;
bool _nackEnabled;
// Uses
ViEEncoderObserver* _codecObserver;
ViEEffectFilter* _effectFilter;
ProcessThread& _moduleProcessThread;
// Recording.
ViEFileRecorder& GetOutgoingFileRecorder();
bool _hasReceivedSLI;
WebRtc_UWord8 _pictureIdSLI;
bool _hasReceivedRPSI;
WebRtc_UWord64 _pictureIdRPSI;
private:
WebRtc_Word32 engine_id_;
WebRtc_Word32 channel_id_;
const WebRtc_UWord32 number_of_cores_;
//Recording
ViEFileRecorder _fileRecorder;
VideoCodingModule& vcm_;
VideoProcessingModule& vpm_;
RtpRtcp& default_rtp_rtcp_;
CriticalSectionWrapper& callback_critsect_;
CriticalSectionWrapper& data_critsect_;
VideoCodec send_codec_;
// Quality modes callback
QMTestVideoSettingsCallback* _qmCallback;
bool paused_;
WebRtc_Word64 time_last_intra_request_ms_[kMaxSimulcastStreams];
WebRtc_Word32 channels_dropping_delta_frames_;
bool drop_next_frame_;
bool fec_enabled_;
bool nack_enabled_;
ViEEncoderObserver* codec_observer_;
ViEEffectFilter* effect_filter_;
ProcessThread& module_process_thread_;
bool has_received_sli_;
WebRtc_UWord8 picture_id_sli_;
bool has_received_rpsi_;
WebRtc_UWord64 picture_id_rpsi_;
ViEFileRecorder file_recorder_;
// Quality modes callback
QMTestVideoSettingsCallback* qm_callback_;
};
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCODER_H_
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_