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