andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | #ifndef WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_ |
| 12 | #define WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_ |
| 13 | |
mflodman@webrtc.org | b6d9cfc | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 14 | #include <list> |
| 15 | #include <map> |
| 16 | |
pbos@webrtc.org | 281cff8 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 17 | #include "webrtc/common_types.h" |
| 18 | #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 19 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
| 20 | #include "webrtc/modules/video_coding/main/interface/video_coding_defines.h" |
| 21 | #include "webrtc/modules/video_processing/main/interface/video_processing.h" |
| 22 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 23 | #include "webrtc/typedefs.h" |
| 24 | #include "webrtc/video_engine/vie_defines.h" |
pbos@webrtc.org | 281cff8 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 25 | #include "webrtc/video_engine/vie_frame_provider_base.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 29 | class Config; |
mflodman@webrtc.org | bf76ae2 | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 30 | class CriticalSectionWrapper; |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 31 | class PacedSender; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 32 | class ProcessThread; |
| 33 | class QMVideoSettingsCallback; |
| 34 | class RtpRtcp; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 35 | class ViEBitrateObserver; |
| 36 | class ViEEffectFilter; |
| 37 | class ViEEncoderObserver; |
mflodman@webrtc.org | bf76ae2 | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 38 | class VideoCodingModule; |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 39 | class ViEPacedSenderCallback; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 40 | |
| 41 | class ViEEncoder |
| 42 | : public RtcpIntraFrameObserver, |
| 43 | public VCMPacketizationCallback, |
| 44 | public VCMProtectionCallback, |
| 45 | public VCMSendStatisticsCallback, |
| 46 | public ViEFrameCallback { |
| 47 | public: |
| 48 | friend class ViEBitrateObserver; |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 49 | friend class ViEPacedSenderCallback; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 50 | |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 51 | ViEEncoder(int32_t engine_id, |
| 52 | int32_t channel_id, |
| 53 | uint32_t number_of_cores, |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 54 | const Config& config, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 55 | ProcessThread& module_process_thread, |
| 56 | BitrateController* bitrate_controller); |
| 57 | ~ViEEncoder(); |
| 58 | |
| 59 | bool Init(); |
| 60 | |
stefan@webrtc.org | dca71b2 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 61 | void SetNetworkTransmissionState(bool is_transmitting); |
| 62 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 63 | // Returns the id of the owning channel. |
| 64 | int Owner() const; |
| 65 | |
| 66 | // Drops incoming packets before they get to the encoder. |
| 67 | void Pause(); |
| 68 | void Restart(); |
| 69 | |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 70 | int32_t DropDeltaAfterKey(bool enable); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 71 | |
| 72 | // Codec settings. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 73 | uint8_t NumberOfCodecs(); |
| 74 | int32_t GetCodec(uint8_t list_index, VideoCodec* video_codec); |
| 75 | int32_t RegisterExternalEncoder(VideoEncoder* encoder, |
| 76 | uint8_t pl_type, |
| 77 | bool internal_source); |
| 78 | int32_t DeRegisterExternalEncoder(uint8_t pl_type); |
| 79 | int32_t SetEncoder(const VideoCodec& video_codec); |
| 80 | int32_t GetEncoder(VideoCodec* video_codec); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 81 | |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 82 | int32_t GetCodecConfigParameters( |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 83 | unsigned char config_parameters[kConfigParameterSize], |
| 84 | unsigned char& config_parameters_size); |
| 85 | |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 86 | PacedSender* GetPacedSender(); |
| 87 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 88 | // Scale or crop/pad image. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 89 | int32_t ScaleInputImage(bool enable); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 90 | |
| 91 | // RTP settings. |
| 92 | RtpRtcp* SendRtpRtcpModule(); |
| 93 | |
| 94 | // Implementing ViEFrameCallback. |
| 95 | virtual void DeliverFrame(int id, |
mikhal@webrtc.org | 3bbed74 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 96 | I420VideoFrame* video_frame, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 97 | int num_csrcs = 0, |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 98 | const uint32_t CSRC[kRtpCsrcSize] = NULL); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 99 | virtual void DelayChanged(int id, int frame_delay); |
| 100 | virtual int GetPreferedFrameSettings(int* width, |
| 101 | int* height, |
| 102 | int* frame_rate); |
| 103 | |
| 104 | virtual void ProviderDestroyed(int id) { |
| 105 | return; |
| 106 | } |
| 107 | |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 108 | int32_t SendKeyFrame(); |
| 109 | int32_t SendCodecStatistics(uint32_t* num_key_frames, |
| 110 | uint32_t* num_delta_frames); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 111 | |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 112 | int32_t EstimatedSendBandwidth( |
| 113 | uint32_t* available_bandwidth) const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 114 | |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 115 | int CodecTargetBitrate(uint32_t* bitrate) const; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 116 | // Loss protection. |
wu@webrtc.org | 7fc75bb | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 117 | int32_t UpdateProtectionMethod(bool enable_nack); |
| 118 | bool nack_enabled() const { return nack_enabled_; } |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 119 | |
mikhal@webrtc.org | 9d6fcb3 | 2013-02-15 23:22:18 +0000 | [diff] [blame] | 120 | // Buffering mode. |
| 121 | void SetSenderBufferingMode(int target_delay_ms); |
mikhal@webrtc.org | 0c66de6 | 2013-02-10 18:42:55 +0000 | [diff] [blame] | 122 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 123 | // Implements VCMPacketizationCallback. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 124 | virtual int32_t SendData( |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 125 | FrameType frame_type, |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 126 | uint8_t payload_type, |
| 127 | uint32_t time_stamp, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 128 | int64_t capture_time_ms, |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 129 | const uint8_t* payload_data, |
| 130 | uint32_t payload_size, |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 131 | const RTPFragmentationHeader& fragmentation_header, |
| 132 | const RTPVideoHeader* rtp_video_hdr); |
| 133 | |
| 134 | // Implements VideoProtectionCallback. |
| 135 | virtual int ProtectionRequest( |
| 136 | const FecProtectionParams* delta_fec_params, |
| 137 | const FecProtectionParams* key_fec_params, |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 138 | uint32_t* sent_video_rate_bps, |
| 139 | uint32_t* sent_nack_rate_bps, |
| 140 | uint32_t* sent_fec_rate_bps); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 141 | |
| 142 | // Implements VideoSendStatisticsCallback. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 143 | virtual int32_t SendStatistics(const uint32_t bit_rate, |
| 144 | const uint32_t frame_rate); |
| 145 | int32_t RegisterCodecObserver(ViEEncoderObserver* observer); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 146 | |
| 147 | // Implements RtcpIntraFrameObserver. |
| 148 | virtual void OnReceivedIntraFrameRequest(uint32_t ssrc); |
| 149 | virtual void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id); |
| 150 | virtual void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id); |
| 151 | virtual void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc); |
| 152 | |
mflodman@webrtc.org | b6d9cfc | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 153 | // Sets SSRCs for all streams. |
| 154 | bool SetSsrcs(const std::list<unsigned int>& ssrcs); |
| 155 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 156 | // Effect filter. |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 157 | int32_t RegisterEffectFilter(ViEEffectFilter* effect_filter); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 158 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 159 | // Enables recording of debugging information. |
| 160 | virtual int StartDebugRecording(const char* fileNameUTF8); |
| 161 | |
| 162 | // Disables recording of debugging information. |
| 163 | virtual int StopDebugRecording(); |
| 164 | |
henrik.lundin@webrtc.org | 39079d1 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 165 | // Enables AutoMuter to turn off video when the rate drops below |
| 166 | // |threshold_bps|, and turns back on when the rate goes back up above |
| 167 | // |threshold_bps| + |window_bps|. |
| 168 | virtual void EnableAutoMuting(int threshold_bps, int window_bps); |
| 169 | |
mflodman@webrtc.org | ff9854b | 2012-10-25 13:06:22 +0000 | [diff] [blame] | 170 | int channel_id() const { return channel_id_; } |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 171 | protected: |
| 172 | // Called by BitrateObserver. |
| 173 | void OnNetworkChanged(const uint32_t bitrate_bps, |
| 174 | const uint8_t fraction_lost, |
| 175 | const uint32_t round_trip_time_ms); |
| 176 | |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 177 | // Called by PacedSender. |
hclam@chromium.org | 0f6f7cb | 2013-06-20 20:18:31 +0000 | [diff] [blame] | 178 | bool TimeToSendPacket(uint32_t ssrc, uint16_t sequence_number, |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 179 | int64_t capture_time_ms); |
stefan@webrtc.org | 69f7605 | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 180 | int TimeToSendPadding(int bytes); |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 181 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 182 | private: |
stefan@webrtc.org | dca71b2 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 183 | bool EncoderPaused() const; |
| 184 | |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 185 | int32_t engine_id_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 186 | const int channel_id_; |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 187 | const uint32_t number_of_cores_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 188 | |
| 189 | VideoCodingModule& vcm_; |
| 190 | VideoProcessingModule& vpm_; |
| 191 | scoped_ptr<RtpRtcp> default_rtp_rtcp_; |
| 192 | scoped_ptr<CriticalSectionWrapper> callback_cs_; |
| 193 | scoped_ptr<CriticalSectionWrapper> data_cs_; |
| 194 | scoped_ptr<BitrateObserver> bitrate_observer_; |
pwestin@webrtc.org | 5e87b5f | 2012-11-13 21:12:39 +0000 | [diff] [blame] | 195 | scoped_ptr<PacedSender> paced_sender_; |
| 196 | scoped_ptr<ViEPacedSenderCallback> pacing_callback_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 197 | |
| 198 | BitrateController* bitrate_controller_; |
| 199 | |
stefan@webrtc.org | 69f7605 | 2013-06-17 12:53:37 +0000 | [diff] [blame] | 200 | bool send_padding_; |
stefan@webrtc.org | dca71b2 | 2013-03-27 16:36:01 +0000 | [diff] [blame] | 201 | int target_delay_ms_; |
| 202 | bool network_is_transmitting_; |
| 203 | bool encoder_paused_; |
pwestin@webrtc.org | 36bdba4 | 2013-05-02 19:02:17 +0000 | [diff] [blame] | 204 | bool encoder_paused_and_dropped_frame_; |
mflodman@webrtc.org | b6d9cfc | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 205 | std::map<unsigned int, int64_t> time_last_intra_request_ms_; |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 206 | int32_t channels_dropping_delta_frames_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 207 | bool drop_next_frame_; |
| 208 | |
| 209 | bool fec_enabled_; |
| 210 | bool nack_enabled_; |
| 211 | |
| 212 | ViEEncoderObserver* codec_observer_; |
| 213 | ViEEffectFilter* effect_filter_; |
| 214 | ProcessThread& module_process_thread_; |
| 215 | |
| 216 | bool has_received_sli_; |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 217 | uint8_t picture_id_sli_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 218 | bool has_received_rpsi_; |
pbos@webrtc.org | 67879bc | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 219 | uint64_t picture_id_rpsi_; |
mflodman@webrtc.org | b6d9cfc | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 220 | std::map<unsigned int, int> ssrc_streams_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 221 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 222 | // Quality modes callback |
| 223 | QMVideoSettingsCallback* qm_callback_; |
henrik.lundin@webrtc.org | 39079d1 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 224 | bool video_auto_muted_; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | } // namespace webrtc |
| 228 | |
| 229 | #endif // WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_ |