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