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 | 84d1783 | 2011-12-01 17:02:23 +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 | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 14 | #include "common_types.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | #include "rtp_rtcp_defines.h" |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 16 | #include "typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | #include "video_coding_defines.h" |
| 18 | #include "video_processing.h" |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 19 | #include "vie_defines.h" |
| 20 | #include "vie_file_recorder.h" |
| 21 | #include "vie_frame_provider_base.h" |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 22 | #include "system_wrappers/interface/scoped_ptr.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 25 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | class CriticalSectionWrapper; |
| 27 | class ProcessThread; |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 28 | class QMVideoSettingsCallback; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | class RtpRtcp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | class VideoCodingModule; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 31 | class ViEEffectFilter; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | class ViEEncoderObserver; |
| 33 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 34 | class ViEEncoder |
| 35 | : public RtpVideoFeedback, |
| 36 | public RtcpFeedback, |
| 37 | public VCMPacketizationCallback, |
| 38 | public VCMProtectionCallback, |
| 39 | public VCMSendStatisticsCallback, |
| 40 | public ViEFrameCallback { |
| 41 | public: |
| 42 | ViEEncoder(WebRtc_Word32 engine_id, |
| 43 | WebRtc_Word32 channel_id, |
| 44 | WebRtc_UWord32 number_of_cores, |
| 45 | ProcessThread& module_process_thread); |
| 46 | ~ViEEncoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame^] | 48 | // Returns the id of the owning channel. |
| 49 | int Owner() const; |
| 50 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 51 | // Drops incoming packets before they get to the encoder. |
| 52 | void Pause(); |
| 53 | void Restart(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 55 | WebRtc_Word32 DropDeltaAfterKey(bool enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 57 | // Codec settings. |
| 58 | WebRtc_UWord8 NumberOfCodecs(); |
| 59 | WebRtc_Word32 GetCodec(WebRtc_UWord8 list_index, VideoCodec& video_codec); |
| 60 | WebRtc_Word32 RegisterExternalEncoder(VideoEncoder* encoder, |
| 61 | WebRtc_UWord8 pl_type); |
| 62 | WebRtc_Word32 DeRegisterExternalEncoder(WebRtc_UWord8 pl_type); |
| 63 | WebRtc_Word32 SetEncoder(const VideoCodec& video_codec); |
| 64 | WebRtc_Word32 GetEncoder(VideoCodec& video_codec); |
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 | WebRtc_Word32 GetCodecConfigParameters( |
| 67 | unsigned char config_parameters[kConfigParameterSize], |
| 68 | unsigned char& config_parameters_size); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 70 | // Scale or crop/pad image. |
| 71 | WebRtc_Word32 ScaleInputImage(bool enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 73 | // RTP settings. |
| 74 | RtpRtcp* SendRtpRtcpModule(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 76 | // Implementing ViEFrameCallback. |
| 77 | virtual void DeliverFrame(int id, |
| 78 | VideoFrame& video_frame, |
| 79 | int num_csrcs = 0, |
| 80 | const WebRtc_UWord32 CSRC[kRtpCsrcSize] = NULL); |
| 81 | virtual void DelayChanged(int id, int frame_delay); |
| 82 | virtual int GetPreferedFrameSettings(int& width, |
| 83 | int& height, |
| 84 | int& frame_rate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 86 | virtual void ProviderDestroyed(int id) { |
| 87 | return; |
| 88 | } |
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 | WebRtc_Word32 EncodeFrame(VideoFrame& video_frame); |
| 91 | WebRtc_Word32 SendKeyFrame(); |
| 92 | WebRtc_Word32 SendCodecStatistics(WebRtc_UWord32& num_key_frames, |
| 93 | WebRtc_UWord32& num_delta_frames); |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 94 | WebRtc_Word32 EstimatedSendBandwidth( |
| 95 | WebRtc_UWord32* available_bandwidth) const; |
| 96 | int CodecTargetBitrate(WebRtc_UWord32* bitrate) const; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 97 | // Loss protection. |
| 98 | WebRtc_Word32 UpdateProtectionMethod(); |
marpan@google.com | 80c5d7a | 2011-07-15 21:32:40 +0000 | [diff] [blame] | 99 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 100 | // Implements VCMPacketizationCallback. |
| 101 | virtual WebRtc_Word32 SendData( |
| 102 | const FrameType frame_type, |
| 103 | const WebRtc_UWord8 payload_type, |
| 104 | const WebRtc_UWord32 time_stamp, |
| 105 | const WebRtc_UWord8* payload_data, |
| 106 | const WebRtc_UWord32 payload_size, |
| 107 | const RTPFragmentationHeader& fragmentation_header, |
| 108 | const RTPVideoHeader* rtp_video_hdr); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 110 | // Implements VideoProtectionCallback. |
stefan@webrtc.org | f4c8286 | 2011-12-13 15:38:14 +0000 | [diff] [blame] | 111 | virtual WebRtc_Word32 ProtectionRequest( |
| 112 | WebRtc_UWord8 delta_fecrate, |
| 113 | WebRtc_UWord8 key_fecrate, |
| 114 | bool delta_use_uep_protection, |
| 115 | bool key_use_uep_protection, |
| 116 | bool nack_enabled, |
| 117 | WebRtc_UWord32* sent_video_rate_bps, |
| 118 | WebRtc_UWord32* sent_nack_rate_bps, |
| 119 | WebRtc_UWord32* sent_fec_rate_bps); |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 120 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 121 | // Implements VideoSendStatisticsCallback. |
| 122 | virtual WebRtc_Word32 SendStatistics(const WebRtc_UWord32 bit_rate, |
| 123 | const WebRtc_UWord32 frame_rate); |
| 124 | WebRtc_Word32 RegisterCodecObserver(ViEEncoderObserver* observer); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 125 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 126 | // Implements RtcpFeedback. |
| 127 | virtual void OnSLIReceived(const WebRtc_Word32 id, |
| 128 | const WebRtc_UWord8 picture_id); |
| 129 | virtual void OnRPSIReceived(const WebRtc_Word32 id, |
| 130 | const WebRtc_UWord64 picture_id); |
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 RtpVideoFeedback. |
| 133 | virtual void OnReceivedIntraFrameRequest(const WebRtc_Word32 id, |
| 134 | const FrameType type, |
| 135 | const WebRtc_UWord8 stream_idx); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 137 | virtual void OnNetworkChanged(const WebRtc_Word32 id, |
| 138 | const WebRtc_UWord32 bitrate_bps, |
| 139 | const WebRtc_UWord8 fraction_lost, |
| 140 | const WebRtc_UWord16 round_trip_time_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 142 | // Effect filter. |
| 143 | WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effect_filter); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 145 | // Recording. |
| 146 | ViEFileRecorder& GetOutgoingFileRecorder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 147 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 148 | private: |
| 149 | WebRtc_Word32 engine_id_; |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame^] | 150 | const int channel_id_; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 151 | const WebRtc_UWord32 number_of_cores_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 153 | VideoCodingModule& vcm_; |
| 154 | VideoProcessingModule& vpm_; |
| 155 | RtpRtcp& default_rtp_rtcp_; |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 156 | scoped_ptr<CriticalSectionWrapper> callback_cs_; |
| 157 | scoped_ptr<CriticalSectionWrapper> data_cs_; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 158 | VideoCodec send_codec_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 160 | bool paused_; |
| 161 | WebRtc_Word64 time_last_intra_request_ms_[kMaxSimulcastStreams]; |
| 162 | WebRtc_Word32 channels_dropping_delta_frames_; |
| 163 | bool drop_next_frame_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 164 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 165 | bool fec_enabled_; |
| 166 | bool nack_enabled_; |
| 167 | |
| 168 | ViEEncoderObserver* codec_observer_; |
| 169 | ViEEffectFilter* effect_filter_; |
| 170 | ProcessThread& module_process_thread_; |
| 171 | |
| 172 | bool has_received_sli_; |
| 173 | WebRtc_UWord8 picture_id_sli_; |
| 174 | bool has_received_rpsi_; |
| 175 | WebRtc_UWord64 picture_id_rpsi_; |
| 176 | |
| 177 | ViEFileRecorder file_recorder_; |
| 178 | |
| 179 | // Quality modes callback |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 180 | QMVideoSettingsCallback* qm_callback_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 181 | }; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 +0000 | [diff] [blame] | 182 | |
| 183 | } // namespace webrtc |
| 184 | |
| 185 | #endif // WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_ |