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

Side by Side Diff: webrtc/video_encoder.h

Issue 2434073003: Extract bitrate allocation of spatial/temporal layers out of codec impl. (Closed)
Patch Set: Fixed sign mismatch 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
« webrtc/video/vie_encoder.cc ('K') | « webrtc/video/vie_encoder.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 struct VideoCodec; 28 struct VideoCodec;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR 155 // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR
155 virtual int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) = 0; 156 virtual int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) = 0;
156 157
157 // Inform the encoder about the new target bit rate. 158 // Inform the encoder about the new target bit rate.
158 // 159 //
159 // Input: 160 // Input:
160 // - bitrate : New target bit rate 161 // - bitrate : New target bit rate
161 // - framerate : The target frame rate 162 // - framerate : The target frame rate
162 // 163 //
163 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. 164 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
164 virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) = 0; 165 virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) {
166 RTC_NOTREACHED() << "SetRate(uint32_t, uint32_t) is deprecated.";
167 return -1;
168 }
169
170 // Default fallback: Just use the sum of bitrates as the single target rate.
171 // TODO(sprang): Remove this default implementation when we remove SetRates().
172 virtual int32_t SetRateAllocation(const BitrateAllocation& allocation,
173 uint32_t framerate) {
174 return SetRates(allocation.get_sum_kbps(), framerate);
175 }
165 176
166 virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; } 177 virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; }
167 virtual void OnDroppedFrame() {} 178 virtual void OnDroppedFrame() {}
168 virtual bool SupportsNativeHandle() const { return false; } 179 virtual bool SupportsNativeHandle() const { return false; }
169 virtual const char* ImplementationName() const { return "unknown"; } 180 virtual const char* ImplementationName() const { return "unknown"; }
170 }; 181 };
171 182
172 // Class used to wrap external VideoEncoders to provide a fallback option on 183 // Class used to wrap external VideoEncoders to provide a fallback option on
173 // software encoding when a hardware encoder fails to encode a stream due to 184 // software encoding when a hardware encoder fails to encode a stream due to
174 // hardware restrictions, such as max resolution. 185 // hardware restrictions, such as max resolution.
175 class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder { 186 class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder {
176 public: 187 public:
177 VideoEncoderSoftwareFallbackWrapper(VideoCodecType codec_type, 188 VideoEncoderSoftwareFallbackWrapper(VideoCodecType codec_type,
178 webrtc::VideoEncoder* encoder); 189 webrtc::VideoEncoder* encoder);
179 190
180 int32_t InitEncode(const VideoCodec* codec_settings, 191 int32_t InitEncode(const VideoCodec* codec_settings,
181 int32_t number_of_cores, 192 int32_t number_of_cores,
182 size_t max_payload_size) override; 193 size_t max_payload_size) override;
183 194
184 int32_t RegisterEncodeCompleteCallback( 195 int32_t RegisterEncodeCompleteCallback(
185 EncodedImageCallback* callback) override; 196 EncodedImageCallback* callback) override;
186 197
187 int32_t Release() override; 198 int32_t Release() override;
188 int32_t Encode(const VideoFrame& frame, 199 int32_t Encode(const VideoFrame& frame,
189 const CodecSpecificInfo* codec_specific_info, 200 const CodecSpecificInfo* codec_specific_info,
190 const std::vector<FrameType>* frame_types) override; 201 const std::vector<FrameType>* frame_types) override;
191 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; 202 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
192 203 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation,
193 int32_t SetRates(uint32_t bitrate, uint32_t framerate) override; 204 uint32_t framerate) override;
194 void OnDroppedFrame() override; 205 void OnDroppedFrame() override;
195 bool SupportsNativeHandle() const override; 206 bool SupportsNativeHandle() const override;
196 207
197 private: 208 private:
198 bool InitFallbackEncoder(); 209 bool InitFallbackEncoder();
199 210
200 // Settings used in the last InitEncode call and used if a dynamic fallback to 211 // Settings used in the last InitEncode call and used if a dynamic fallback to
201 // software is required. 212 // software is required.
202 VideoCodec codec_settings_; 213 VideoCodec codec_settings_;
203 int32_t number_of_cores_; 214 int32_t number_of_cores_;
204 size_t max_payload_size_; 215 size_t max_payload_size_;
205 216
206 // The last bitrate/framerate set, and a flag for noting they are set. 217 // The last bitrate/framerate set, and a flag for noting they are set.
207 bool rates_set_; 218 bool rates_set_;
208 uint32_t bitrate_; 219 BitrateAllocation bitrate_;
209 uint32_t framerate_; 220 uint32_t framerate_;
210 221
211 // The last channel parameters set, and a flag for noting they are set. 222 // The last channel parameters set, and a flag for noting they are set.
212 bool channel_parameters_set_; 223 bool channel_parameters_set_;
213 uint32_t packet_loss_; 224 uint32_t packet_loss_;
214 int64_t rtt_; 225 int64_t rtt_;
215 226
216 const EncoderType encoder_type_; 227 const EncoderType encoder_type_;
217 webrtc::VideoEncoder* const encoder_; 228 webrtc::VideoEncoder* const encoder_;
218 229
219 std::unique_ptr<webrtc::VideoEncoder> fallback_encoder_; 230 std::unique_ptr<webrtc::VideoEncoder> fallback_encoder_;
220 std::string fallback_implementation_name_; 231 std::string fallback_implementation_name_;
221 EncodedImageCallback* callback_; 232 EncodedImageCallback* callback_;
222 }; 233 };
223 } // namespace webrtc 234 } // namespace webrtc
224 #endif // WEBRTC_VIDEO_ENCODER_H_ 235 #endif // WEBRTC_VIDEO_ENCODER_H_
OLDNEW
« webrtc/video/vie_encoder.cc ('K') | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698