Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: webrtc/video_encoder.h

Issue 2488833004: Reland of Issue 2434073003: Extract bitrate allocation ... (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/vie_encoder_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_VIDEO_ENCODER_H_ 11 #ifndef WEBRTC_VIDEO_ENCODER_H_
12 #define WEBRTC_VIDEO_ENCODER_H_ 12 #define WEBRTC_VIDEO_ENCODER_H_
13 13
14 #include <memory> 14 #include <memory>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/checks.h"
18 #include "webrtc/common_types.h" 19 #include "webrtc/common_types.h"
19 #include "webrtc/typedefs.h" 20 #include "webrtc/typedefs.h"
20 #include "webrtc/video_frame.h" 21 #include "webrtc/video_frame.h"
21 22
22 namespace webrtc { 23 namespace webrtc {
23 24
24 class RTPFragmentationHeader; 25 class RTPFragmentationHeader;
25 // TODO(pbos): Expose these through a public (root) header or change these APIs. 26 // TODO(pbos): Expose these through a public (root) header or change these APIs.
26 struct CodecSpecificInfo; 27 struct CodecSpecificInfo;
27 class VideoCodec; 28 class VideoCodec;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR 142 // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR
142 virtual int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) = 0; 143 virtual int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) = 0;
143 144
144 // Inform the encoder about the new target bit rate. 145 // Inform the encoder about the new target bit rate.
145 // 146 //
146 // Input: 147 // Input:
147 // - bitrate : New target bit rate 148 // - bitrate : New target bit rate
148 // - framerate : The target frame rate 149 // - framerate : The target frame rate
149 // 150 //
150 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. 151 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
151 virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) = 0; 152 virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) {
153 RTC_NOTREACHED() << "SetRate(uint32_t, uint32_t) is deprecated.";
154 return -1;
155 }
156
157 // Default fallback: Just use the sum of bitrates as the single target rate.
158 // TODO(sprang): Remove this default implementation when we remove SetRates().
159 virtual int32_t SetRateAllocation(const BitrateAllocation& allocation,
160 uint32_t framerate) {
161 return SetRates(allocation.get_sum_kbps(), framerate);
162 }
152 163
153 virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; } 164 virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; }
154 virtual void OnDroppedFrame() {} 165 virtual void OnDroppedFrame() {}
155 virtual bool SupportsNativeHandle() const { return false; } 166 virtual bool SupportsNativeHandle() const { return false; }
156 virtual const char* ImplementationName() const { return "unknown"; } 167 virtual const char* ImplementationName() const { return "unknown"; }
157 }; 168 };
158 169
159 // Class used to wrap external VideoEncoders to provide a fallback option on 170 // Class used to wrap external VideoEncoders to provide a fallback option on
160 // software encoding when a hardware encoder fails to encode a stream due to 171 // software encoding when a hardware encoder fails to encode a stream due to
161 // hardware restrictions, such as max resolution. 172 // hardware restrictions, such as max resolution.
162 class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder { 173 class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder {
163 public: 174 public:
164 VideoEncoderSoftwareFallbackWrapper(VideoCodecType codec_type, 175 VideoEncoderSoftwareFallbackWrapper(VideoCodecType codec_type,
165 webrtc::VideoEncoder* encoder); 176 webrtc::VideoEncoder* encoder);
166 177
167 int32_t InitEncode(const VideoCodec* codec_settings, 178 int32_t InitEncode(const VideoCodec* codec_settings,
168 int32_t number_of_cores, 179 int32_t number_of_cores,
169 size_t max_payload_size) override; 180 size_t max_payload_size) override;
170 181
171 int32_t RegisterEncodeCompleteCallback( 182 int32_t RegisterEncodeCompleteCallback(
172 EncodedImageCallback* callback) override; 183 EncodedImageCallback* callback) override;
173 184
174 int32_t Release() override; 185 int32_t Release() override;
175 int32_t Encode(const VideoFrame& frame, 186 int32_t Encode(const VideoFrame& frame,
176 const CodecSpecificInfo* codec_specific_info, 187 const CodecSpecificInfo* codec_specific_info,
177 const std::vector<FrameType>* frame_types) override; 188 const std::vector<FrameType>* frame_types) override;
178 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; 189 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
179 190 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation,
180 int32_t SetRates(uint32_t bitrate, uint32_t framerate) override; 191 uint32_t framerate) override;
181 void OnDroppedFrame() override; 192 void OnDroppedFrame() override;
182 bool SupportsNativeHandle() const override; 193 bool SupportsNativeHandle() const override;
183 194
184 private: 195 private:
185 bool InitFallbackEncoder(); 196 bool InitFallbackEncoder();
186 197
187 // Settings used in the last InitEncode call and used if a dynamic fallback to 198 // Settings used in the last InitEncode call and used if a dynamic fallback to
188 // software is required. 199 // software is required.
189 VideoCodec codec_settings_; 200 VideoCodec codec_settings_;
190 int32_t number_of_cores_; 201 int32_t number_of_cores_;
191 size_t max_payload_size_; 202 size_t max_payload_size_;
192 203
193 // The last bitrate/framerate set, and a flag for noting they are set. 204 // The last bitrate/framerate set, and a flag for noting they are set.
194 bool rates_set_; 205 bool rates_set_;
195 uint32_t bitrate_; 206 BitrateAllocation bitrate_allocation_;
196 uint32_t framerate_; 207 uint32_t framerate_;
197 208
198 // The last channel parameters set, and a flag for noting they are set. 209 // The last channel parameters set, and a flag for noting they are set.
199 bool channel_parameters_set_; 210 bool channel_parameters_set_;
200 uint32_t packet_loss_; 211 uint32_t packet_loss_;
201 int64_t rtt_; 212 int64_t rtt_;
202 213
203 const EncoderType encoder_type_; 214 const EncoderType encoder_type_;
204 webrtc::VideoEncoder* const encoder_; 215 webrtc::VideoEncoder* const encoder_;
205 216
206 std::unique_ptr<webrtc::VideoEncoder> fallback_encoder_; 217 std::unique_ptr<webrtc::VideoEncoder> fallback_encoder_;
207 std::string fallback_implementation_name_; 218 std::string fallback_implementation_name_;
208 EncodedImageCallback* callback_; 219 EncodedImageCallback* callback_;
209 }; 220 };
210 } // namespace webrtc 221 } // namespace webrtc
211 #endif // WEBRTC_VIDEO_ENCODER_H_ 222 #endif // WEBRTC_VIDEO_ENCODER_H_
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698