niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * vie_encoder.h |
| 13 | */ |
| 14 | |
| 15 | #ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCODER_H_ |
| 16 | #define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCODER_H_ |
| 17 | |
| 18 | #include "vie_defines.h" |
| 19 | #include "typedefs.h" |
| 20 | #include "vie_frame_provider_base.h" |
| 21 | #include "vie_file_recorder.h" |
| 22 | #include "rtp_rtcp_defines.h" |
| 23 | #include "video_coding_defines.h" |
| 24 | #include "video_processing.h" |
| 25 | #include "common_types.h" |
| 26 | |
| 27 | namespace webrtc { |
| 28 | class CriticalSectionWrapper; |
| 29 | class ProcessThread; |
| 30 | class RtpRtcp; |
| 31 | class ViEEffectFilter; |
| 32 | class VideoCodingModule; |
| 33 | class ViEEncoderObserver; |
| 34 | |
| 35 | class ViEEncoder: public ViEFrameCallback, // New frame delivery |
| 36 | public RtpVideoFeedback, // Feedback from RTP module |
| 37 | public RtcpFeedback, // RTP/RTCP Module |
| 38 | public VCMPacketizationCallback, // Callback from VCM |
| 39 | public VCMProtectionCallback, // Callback from VCM |
| 40 | public VCMSendStatisticsCallback // Callback from VCM |
| 41 | { |
| 42 | public: |
| 43 | ViEEncoder(WebRtc_Word32 engineId, WebRtc_Word32 channelId, |
| 44 | WebRtc_UWord32 numberOfCores, |
| 45 | ProcessThread& moduleProcessThread); |
| 46 | ~ViEEncoder(); |
| 47 | |
| 48 | // Drops incoming packets |
| 49 | void Pause(); |
| 50 | void Restart(); |
| 51 | |
| 52 | WebRtc_Word32 DropDeltaAfterKey(bool enable); |
| 53 | |
| 54 | // Codec settings |
| 55 | WebRtc_UWord8 NumberOfCodecs(); |
| 56 | WebRtc_Word32 GetCodec(WebRtc_UWord8 listIndex, VideoCodec& videoCodec); |
| 57 | WebRtc_Word32 RegisterExternalEncoder(VideoEncoder* encoder, |
| 58 | WebRtc_UWord8 plType); |
| 59 | WebRtc_Word32 DeRegisterExternalEncoder(WebRtc_UWord8 plType); |
| 60 | WebRtc_Word32 SetEncoder(const VideoCodec& videoCodec); |
| 61 | WebRtc_Word32 GetEncoder(VideoCodec& videoCodec); |
| 62 | |
| 63 | WebRtc_Word32 GetCodecConfigParameters( |
| 64 | unsigned char configParameters[kConfigParameterSize], |
| 65 | unsigned char& configParametersSize); |
| 66 | |
| 67 | // Scale or crop/pad image |
| 68 | WebRtc_Word32 ScaleInputImage(bool enable); |
| 69 | |
| 70 | // RTP settings |
| 71 | RtpRtcp* SendRtpRtcpModule(); |
| 72 | |
| 73 | // Implementing ViEFrameCallback |
| 74 | virtual void DeliverFrame(int id, VideoFrame& videoFrame, int numCSRCs = 0, |
| 75 | const WebRtc_UWord32 CSRC[kRtpCsrcSize] = NULL); |
| 76 | virtual void DelayChanged(int id, int frameDelay); |
| 77 | virtual int GetPreferedFrameSettings(int &width, int &height, |
| 78 | int &frameRate); |
| 79 | |
| 80 | virtual void ProviderDestroyed(int id) { return; } |
| 81 | |
| 82 | WebRtc_Word32 EncodeFrame(VideoFrame& videoFrame); |
| 83 | WebRtc_Word32 SendKeyFrame(); |
| 84 | WebRtc_Word32 SendCodecStatistics(WebRtc_UWord32& numKeyFrames, |
| 85 | WebRtc_UWord32& numDeltaFrames); |
| 86 | // Loss protection |
| 87 | WebRtc_Word32 UpdateProtectionMethod(); |
| 88 | // Implements VCMPacketizationCallback |
| 89 | virtual WebRtc_Word32 |
| 90 | SendData(const FrameType frameType, |
| 91 | const WebRtc_UWord8 payloadType, |
| 92 | const WebRtc_UWord32 timeStamp, |
| 93 | const WebRtc_UWord8* payloadData, |
| 94 | const WebRtc_UWord32 payloadSize, |
| 95 | const RTPFragmentationHeader& fragmentationHeader, |
| 96 | const RTPVideoTypeHeader* rtpTypeHdr); |
| 97 | // Implements VideoProtectionCallback |
| 98 | virtual WebRtc_Word32 ProtectionRequest(const WebRtc_UWord8 deltaFECRate, |
| 99 | const WebRtc_UWord8 keyFECRate, |
marpan@google.com | 80c5d7a | 2011-07-15 21:32:40 +0000 | [diff] [blame^] | 100 | const bool deltaUseUepProtection, |
| 101 | const bool keyUseUepProtection, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | const bool nack); |
marpan@google.com | 80c5d7a | 2011-07-15 21:32:40 +0000 | [diff] [blame^] | 103 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | // Implements VideoSendStatisticsCallback |
| 105 | virtual WebRtc_Word32 SendStatistics(const WebRtc_UWord32 bitRate, |
| 106 | const WebRtc_UWord32 frameRate); |
| 107 | WebRtc_Word32 RegisterCodecObserver(ViEEncoderObserver* observer); |
| 108 | // Implements RtcpFeedback |
| 109 | virtual void OnSLIReceived(const WebRtc_Word32 id, |
| 110 | const WebRtc_UWord8 pictureId); |
| 111 | virtual void OnRPSIReceived(const WebRtc_Word32 id, |
| 112 | const WebRtc_UWord64 pictureId); |
| 113 | |
| 114 | // Implements RtpVideoFeedback |
| 115 | virtual void OnReceivedIntraFrameRequest(const WebRtc_Word32 id, |
| 116 | const WebRtc_UWord8 message = 0); |
| 117 | virtual void OnNetworkChanged(const WebRtc_Word32 id, |
| 118 | const WebRtc_UWord32 minBitrateBps, |
| 119 | const WebRtc_UWord32 maxBitrateBps, |
| 120 | const WebRtc_UWord8 fractionLost, |
| 121 | const WebRtc_UWord16 roundTripTimeMs, |
| 122 | const WebRtc_UWord16 bwEstimateKbitMin, |
| 123 | const WebRtc_UWord16 bwEstimateKbitMax); |
| 124 | // Effect filter |
| 125 | WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effectFilter); |
| 126 | //Recording |
| 127 | ViEFileRecorder& GetOutgoingFileRecorder(); |
| 128 | |
| 129 | private: |
| 130 | WebRtc_Word32 _engineId; |
| 131 | |
| 132 | class QMTestVideoSettingsCallback : public VCMQMSettingsCallback |
| 133 | { |
| 134 | public: |
| 135 | QMTestVideoSettingsCallback(); |
| 136 | // update VPM with QM (quality modes: frame size & frame rate) settings |
| 137 | WebRtc_Word32 SetVideoQMSettings(const WebRtc_UWord32 frameRate, |
| 138 | const WebRtc_UWord32 width, |
| 139 | const WebRtc_UWord32 height); |
| 140 | // register VPM and VCM |
| 141 | void RegisterVPM(VideoProcessingModule* vpm); |
| 142 | void RegisterVCM(VideoCodingModule* vcm); |
| 143 | void SetNumOfCores(WebRtc_Word32 numOfCores) |
| 144 | {_numOfCores = numOfCores;}; |
| 145 | void SetMaxPayloadLength(WebRtc_Word32 maxPayloadLength) |
| 146 | {_maxPayloadLength = maxPayloadLength;}; |
| 147 | private: |
| 148 | VideoProcessingModule* _vpm; |
| 149 | VideoCodingModule* _vcm; |
| 150 | WebRtc_Word32 _numOfCores; |
| 151 | WebRtc_Word32 _maxPayloadLength; |
| 152 | }; |
| 153 | |
| 154 | WebRtc_Word32 _channelId; |
| 155 | const WebRtc_UWord32 _numberOfCores; |
| 156 | |
| 157 | VideoCodingModule& _vcm; |
| 158 | VideoProcessingModule& _vpm; |
| 159 | RtpRtcp& _rtpRtcp; |
| 160 | CriticalSectionWrapper& _callbackCritsect; |
| 161 | CriticalSectionWrapper& _dataCritsect; |
| 162 | VideoCodec _sendCodec; |
| 163 | |
| 164 | bool _paused; |
| 165 | WebRtc_Word64 _timeLastIntraRequestMs; |
| 166 | WebRtc_Word32 _channelsDroppingDeltaFrames; |
| 167 | bool _dropNextFrame; |
| 168 | //Loss protection |
| 169 | bool _fecEnabled; |
| 170 | bool _nackEnabled; |
| 171 | // Uses |
| 172 | ViEEncoderObserver* _codecObserver; |
| 173 | ViEEffectFilter* _effectFilter; |
| 174 | ProcessThread& _moduleProcessThread; |
| 175 | |
| 176 | bool _hasReceivedSLI; |
| 177 | WebRtc_UWord8 _pictureIdSLI; |
| 178 | bool _hasReceivedRPSI; |
| 179 | WebRtc_UWord64 _pictureIdRPSI; |
| 180 | |
| 181 | //Recording |
| 182 | ViEFileRecorder _fileRecorder; |
| 183 | |
| 184 | // Quality modes callback |
| 185 | QMTestVideoSettingsCallback* _qmCallback; |
| 186 | |
| 187 | }; |
| 188 | } // namespace webrtc |
| 189 | #endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCODER_H_ |