blob: dc74f3339a643546fd66b580977175d342368e6a [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
14#include <list>
15#include <map>
16
17#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,
87 VideoFrame* video_frame,
88 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
140 // Sets SSRCs for all streams.
141 bool SetSsrcs(const std::list<unsigned int>& ssrcs);
142
143 // 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
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
161 private:
162 WebRtc_Word32 engine_id_;
163 const int channel_id_;
164 const WebRtc_UWord32 number_of_cores_;
165
166 VideoCodingModule& vcm_;
167 VideoProcessingModule& vpm_;
168 scoped_ptr<RtpRtcp> default_rtp_rtcp_;
169 scoped_ptr<CriticalSectionWrapper> callback_cs_;
170 scoped_ptr<CriticalSectionWrapper> data_cs_;
171 scoped_ptr<BitrateObserver> bitrate_observer_;
172
173 BitrateController* bitrate_controller_;
174
175 bool paused_;
176 std::map<unsigned int, int64_t> time_last_intra_request_ms_;
177 WebRtc_Word32 channels_dropping_delta_frames_;
178 bool drop_next_frame_;
179
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_;
191 std::map<unsigned int, int> ssrc_streams_;
192
193 ViEFileRecorder file_recorder_;
194
195 // Quality modes callback
196 QMVideoSettingsCallback* qm_callback_;
197};
198
199} // namespace webrtc
200
201#endif // WEBRTC_VIDEO_ENGINE_VIE_ENCODER_H_