blob: ea552bf06361af8453b46262ca866b3ac3a8d58c [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
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.orgb6d9cfc2012-10-25 11:30:29 +000014#include <list>
15#include <map>
16
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000017#include "common_types.h" // NOLINT
18#include "typedefs.h" //NOLINT
19#include "modules/bitrate_controller/include/bitrate_controller.h"
20#include "modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
21#include "modules/video_coding/main/interface/video_coding_defines.h"
22#include "modules/video_processing/main/interface/video_processing.h"
23#include "system_wrappers/interface/scoped_ptr.h"
24#include "video_engine/vie_defines.h"
25#include "video_engine/vie_file_recorder.h"
26#include "video_engine/vie_frame_provider_base.h"
27
28namespace webrtc {
29
30class CriticalSectionWrapper;
31class ProcessThread;
32class QMVideoSettingsCallback;
33class RtpRtcp;
34class VideoCodingModule;
35class ViEBitrateObserver;
36class ViEEffectFilter;
37class ViEEncoderObserver;
38
39class ViEEncoder
40 : public RtcpIntraFrameObserver,
41 public VCMPacketizationCallback,
42 public VCMProtectionCallback,
43 public VCMSendStatisticsCallback,
44 public ViEFrameCallback {
45 public:
46 friend class ViEBitrateObserver;
47
48 ViEEncoder(WebRtc_Word32 engine_id,
49 WebRtc_Word32 channel_id,
50 WebRtc_UWord32 number_of_cores,
51 ProcessThread& module_process_thread,
52 BitrateController* bitrate_controller);
53 ~ViEEncoder();
54
55 bool Init();
56
57 // Returns the id of the owning channel.
58 int Owner() const;
59
60 // Drops incoming packets before they get to the encoder.
61 void Pause();
62 void Restart();
63
64 WebRtc_Word32 DropDeltaAfterKey(bool enable);
65
66 // Codec settings.
67 WebRtc_UWord8 NumberOfCodecs();
68 WebRtc_Word32 GetCodec(WebRtc_UWord8 list_index, VideoCodec* video_codec);
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);
73 WebRtc_Word32 GetEncoder(VideoCodec* video_codec);
74
75 WebRtc_Word32 GetCodecConfigParameters(
76 unsigned char config_parameters[kConfigParameterSize],
77 unsigned char& config_parameters_size);
78
79 // Scale or crop/pad image.
80 WebRtc_Word32 ScaleInputImage(bool enable);
81
82 // RTP settings.
83 RtpRtcp* SendRtpRtcpModule();
84
85 // Implementing ViEFrameCallback.
86 virtual void DeliverFrame(int id,
mikhal@webrtc.org3bbed742012-10-24 18:33:04 +000087 I420VideoFrame* video_frame,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000088 int num_csrcs = 0,
89 const WebRtc_UWord32 CSRC[kRtpCsrcSize] = NULL);
90 virtual void DelayChanged(int id, int frame_delay);
91 virtual int GetPreferedFrameSettings(int* width,
92 int* height,
93 int* frame_rate);
94
95 virtual void ProviderDestroyed(int id) {
96 return;
97 }
98
99 WebRtc_Word32 SendKeyFrame();
100 WebRtc_Word32 SendCodecStatistics(WebRtc_UWord32* num_key_frames,
101 WebRtc_UWord32* num_delta_frames);
102
103 WebRtc_Word32 EstimatedSendBandwidth(
104 WebRtc_UWord32* available_bandwidth) const;
105
106 int CodecTargetBitrate(WebRtc_UWord32* bitrate) const;
107 // Loss protection.
108 WebRtc_Word32 UpdateProtectionMethod();
109
110 // Implements VCMPacketizationCallback.
111 virtual WebRtc_Word32 SendData(
112 FrameType frame_type,
113 WebRtc_UWord8 payload_type,
114 WebRtc_UWord32 time_stamp,
115 int64_t capture_time_ms,
116 const WebRtc_UWord8* payload_data,
117 WebRtc_UWord32 payload_size,
118 const RTPFragmentationHeader& fragmentation_header,
119 const RTPVideoHeader* rtp_video_hdr);
120
121 // Implements VideoProtectionCallback.
122 virtual int ProtectionRequest(
123 const FecProtectionParams* delta_fec_params,
124 const FecProtectionParams* key_fec_params,
125 WebRtc_UWord32* sent_video_rate_bps,
126 WebRtc_UWord32* sent_nack_rate_bps,
127 WebRtc_UWord32* sent_fec_rate_bps);
128
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);
133
134 // Implements RtcpIntraFrameObserver.
135 virtual void OnReceivedIntraFrameRequest(uint32_t ssrc);
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);
139
mflodman@webrtc.orgb6d9cfc2012-10-25 11:30:29 +0000140 // Sets SSRCs for all streams.
141 bool SetSsrcs(const std::list<unsigned int>& ssrcs);
142
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000143 // Effect filter.
144 WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effect_filter);
145
146 // Recording.
147 ViEFileRecorder& GetOutgoingFileRecorder();
148
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
mflodman@webrtc.orgff9854b2012-10-25 13:06:22 +0000155 int channel_id() const { return channel_id_; }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000156 protected:
157 // Called by BitrateObserver.
158 void OnNetworkChanged(const uint32_t bitrate_bps,
159 const uint8_t fraction_lost,
160 const uint32_t round_trip_time_ms);
161
162 private:
163 WebRtc_Word32 engine_id_;
164 const int channel_id_;
165 const WebRtc_UWord32 number_of_cores_;
166
167 VideoCodingModule& vcm_;
168 VideoProcessingModule& vpm_;
169 scoped_ptr<RtpRtcp> default_rtp_rtcp_;
170 scoped_ptr<CriticalSectionWrapper> callback_cs_;
171 scoped_ptr<CriticalSectionWrapper> data_cs_;
172 scoped_ptr<BitrateObserver> bitrate_observer_;
173
174 BitrateController* bitrate_controller_;
175
176 bool paused_;
mflodman@webrtc.orgb6d9cfc2012-10-25 11:30:29 +0000177 std::map<unsigned int, int64_t> time_last_intra_request_ms_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000178 WebRtc_Word32 channels_dropping_delta_frames_;
179 bool drop_next_frame_;
180
181 bool fec_enabled_;
182 bool nack_enabled_;
183
184 ViEEncoderObserver* codec_observer_;
185 ViEEffectFilter* effect_filter_;
186 ProcessThread& module_process_thread_;
187
188 bool has_received_sli_;
189 WebRtc_UWord8 picture_id_sli_;
190 bool has_received_rpsi_;
191 WebRtc_UWord64 picture_id_rpsi_;
mflodman@webrtc.orgb6d9cfc2012-10-25 11:30:29 +0000192 std::map<unsigned int, int> ssrc_streams_;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000193
194 ViEFileRecorder file_recorder_;
195
196 // Quality modes callback
197 QMVideoSettingsCallback* qm_callback_;
198};
199
200} // namespace webrtc
201
202#endif // WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_