blob: f2e7f9e6e65294a920082c4b8d1632ebfb31941b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
stefan@webrtc.org07b45a52012-02-02 08:37:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org84d17832011-12-01 17:02:23 +000011#ifndef WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_
12#define WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000014#include "common_types.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015#include "rtp_rtcp_defines.h"
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000016#include "typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017#include "video_coding_defines.h"
18#include "video_processing.h"
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000019#include "vie_defines.h"
20#include "vie_file_recorder.h"
21#include "vie_frame_provider_base.h"
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +000022#include "system_wrappers/interface/scoped_ptr.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24namespace webrtc {
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000025
niklase@google.com470e71d2011-07-07 08:21:25 +000026class CriticalSectionWrapper;
27class ProcessThread;
stefan@webrtc.org439be292012-02-16 14:45:37 +000028class QMVideoSettingsCallback;
niklase@google.com470e71d2011-07-07 08:21:25 +000029class RtpRtcp;
niklase@google.com470e71d2011-07-07 08:21:25 +000030class VideoCodingModule;
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000031class ViEEffectFilter;
niklase@google.com470e71d2011-07-07 08:21:25 +000032class ViEEncoderObserver;
33
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000034class 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.com470e71d2011-07-07 08:21:25 +000047
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000048 // Returns the id of the owning channel.
49 int Owner() const;
50
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000051 // Drops incoming packets before they get to the encoder.
52 void Pause();
53 void Restart();
niklase@google.com470e71d2011-07-07 08:21:25 +000054
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000055 WebRtc_Word32 DropDeltaAfterKey(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +000056
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000057 // 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.com470e71d2011-07-07 08:21:25 +000065
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000066 WebRtc_Word32 GetCodecConfigParameters(
67 unsigned char config_parameters[kConfigParameterSize],
68 unsigned char& config_parameters_size);
niklase@google.com470e71d2011-07-07 08:21:25 +000069
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000070 // Scale or crop/pad image.
71 WebRtc_Word32 ScaleInputImage(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +000072
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000073 // RTP settings.
74 RtpRtcp* SendRtpRtcpModule();
niklase@google.com470e71d2011-07-07 08:21:25 +000075
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000076 // 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.com470e71d2011-07-07 08:21:25 +000085
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000086 virtual void ProviderDestroyed(int id) {
87 return;
88 }
niklase@google.com470e71d2011-07-07 08:21:25 +000089
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000090 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.org439be292012-02-16 14:45:37 +000094 WebRtc_Word32 EstimatedSendBandwidth(
95 WebRtc_UWord32* available_bandwidth) const;
96 int CodecTargetBitrate(WebRtc_UWord32* bitrate) const;
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000097 // Loss protection.
98 WebRtc_Word32 UpdateProtectionMethod();
marpan@google.com80c5d7a2011-07-15 21:32:40 +000099
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000100 // 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.com470e71d2011-07-07 08:21:25 +0000109
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000110 // Implements VideoProtectionCallback.
stefan@webrtc.orgf4c82862011-12-13 15:38:14 +0000111 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.org1da1ce02011-10-13 15:19:55 +0000120
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000121 // 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.com470e71d2011-07-07 08:21:25 +0000125
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000126 // 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.com470e71d2011-07-07 08:21:25 +0000131
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000132 // Implements RtpVideoFeedback.
133 virtual void OnReceivedIntraFrameRequest(const WebRtc_Word32 id,
134 const FrameType type,
135 const WebRtc_UWord8 stream_idx);
niklase@google.com470e71d2011-07-07 08:21:25 +0000136
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000137 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.com470e71d2011-07-07 08:21:25 +0000141
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000142 // Effect filter.
143 WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effect_filter);
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000145 // Recording.
146 ViEFileRecorder& GetOutgoingFileRecorder();
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000148 private:
149 WebRtc_Word32 engine_id_;
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000150 const int channel_id_;
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000151 const WebRtc_UWord32 number_of_cores_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000153 VideoCodingModule& vcm_;
154 VideoProcessingModule& vpm_;
155 RtpRtcp& default_rtp_rtcp_;
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000156 scoped_ptr<CriticalSectionWrapper> callback_cs_;
157 scoped_ptr<CriticalSectionWrapper> data_cs_;
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000158 VideoCodec send_codec_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000159
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000160 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.com470e71d2011-07-07 08:21:25 +0000164
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000165 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.org439be292012-02-16 14:45:37 +0000180 QMVideoSettingsCallback* qm_callback_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000181};
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000182
183} // namespace webrtc
184
185#endif // WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_