OLD | NEW |
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/common_types.h" | 18 #include "webrtc/common_types.h" |
19 #include "webrtc/typedefs.h" | 19 #include "webrtc/typedefs.h" |
20 #include "webrtc/video_frame.h" | 20 #include "webrtc/video_frame.h" |
| 21 #include "webrtc/base/optional.h" |
| 22 #include "webrtc/modules/video_coding/utility/quality_scaler.h" |
21 | 23 |
22 namespace webrtc { | 24 namespace webrtc { |
23 | 25 |
24 class RTPFragmentationHeader; | 26 class RTPFragmentationHeader; |
25 // TODO(pbos): Expose these through a public (root) header or change these APIs. | 27 // TODO(pbos): Expose these through a public (root) header or change these APIs. |
26 struct CodecSpecificInfo; | 28 struct CodecSpecificInfo; |
27 struct VideoCodec; | 29 struct VideoCodec; |
28 | 30 |
29 class EncodedImageCallback { | 31 class EncodedImageCallback { |
30 public: | 32 public: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 }; | 76 }; |
75 | 77 |
76 class VideoEncoder { | 78 class VideoEncoder { |
77 public: | 79 public: |
78 enum EncoderType { | 80 enum EncoderType { |
79 kH264, | 81 kH264, |
80 kVp8, | 82 kVp8, |
81 kVp9, | 83 kVp9, |
82 kUnsupportedCodec, | 84 kUnsupportedCodec, |
83 }; | 85 }; |
84 | |
85 static VideoEncoder* Create(EncoderType codec_type); | 86 static VideoEncoder* Create(EncoderType codec_type); |
86 | 87 |
87 static VideoCodecVP8 GetDefaultVp8Settings(); | 88 static VideoCodecVP8 GetDefaultVp8Settings(); |
88 static VideoCodecVP9 GetDefaultVp9Settings(); | 89 static VideoCodecVP9 GetDefaultVp9Settings(); |
89 static VideoCodecH264 GetDefaultH264Settings(); | 90 static VideoCodecH264 GetDefaultH264Settings(); |
90 | 91 |
91 virtual ~VideoEncoder() {} | 92 virtual ~VideoEncoder() {} |
92 | 93 |
93 // Initialize the encoder with the information from the codecSettings | 94 // Initialize the encoder with the information from the codecSettings |
94 // | 95 // |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 153 |
153 // Inform the encoder about the new target bit rate. | 154 // Inform the encoder about the new target bit rate. |
154 // | 155 // |
155 // Input: | 156 // Input: |
156 // - bitrate : New target bit rate | 157 // - bitrate : New target bit rate |
157 // - framerate : The target frame rate | 158 // - framerate : The target frame rate |
158 // | 159 // |
159 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. | 160 // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. |
160 virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) = 0; | 161 virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) = 0; |
161 | 162 |
| 163 // Any encoder implementation wishing to use the WebRTC provided |
| 164 // quality scaler must implement this method. |
| 165 virtual QualityScaler::Settings GetQPThresholds() const { |
| 166 return QualityScaler::Settings(false); |
| 167 } |
| 168 |
162 virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; } | 169 virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; } |
163 virtual void OnDroppedFrame() {} | 170 virtual void OnDroppedFrame() {} |
164 virtual bool SupportsNativeHandle() const { return false; } | 171 virtual bool SupportsNativeHandle() const { return false; } |
165 virtual const char* ImplementationName() const { return "unknown"; } | 172 virtual const char* ImplementationName() const { return "unknown"; } |
166 }; | 173 }; |
167 | 174 |
168 // Class used to wrap external VideoEncoders to provide a fallback option on | 175 // Class used to wrap external VideoEncoders to provide a fallback option on |
169 // software encoding when a hardware encoder fails to encode a stream due to | 176 // software encoding when a hardware encoder fails to encode a stream due to |
170 // hardware restrictions, such as max resolution. | 177 // hardware restrictions, such as max resolution. |
171 class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder { | 178 class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder { |
(...skipping 10 matching lines...) Expand all Loading... |
182 | 189 |
183 int32_t Release() override; | 190 int32_t Release() override; |
184 int32_t Encode(const VideoFrame& frame, | 191 int32_t Encode(const VideoFrame& frame, |
185 const CodecSpecificInfo* codec_specific_info, | 192 const CodecSpecificInfo* codec_specific_info, |
186 const std::vector<FrameType>* frame_types) override; | 193 const std::vector<FrameType>* frame_types) override; |
187 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; | 194 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; |
188 | 195 |
189 int32_t SetRates(uint32_t bitrate, uint32_t framerate) override; | 196 int32_t SetRates(uint32_t bitrate, uint32_t framerate) override; |
190 void OnDroppedFrame() override; | 197 void OnDroppedFrame() override; |
191 bool SupportsNativeHandle() const override; | 198 bool SupportsNativeHandle() const override; |
| 199 QualityScaler::Settings GetQPThresholds() const override; |
192 | 200 |
193 private: | 201 private: |
194 bool InitFallbackEncoder(); | 202 bool InitFallbackEncoder(); |
195 | 203 |
196 // Settings used in the last InitEncode call and used if a dynamic fallback to | 204 // Settings used in the last InitEncode call and used if a dynamic fallback to |
197 // software is required. | 205 // software is required. |
198 VideoCodec codec_settings_; | 206 VideoCodec codec_settings_; |
199 int32_t number_of_cores_; | 207 int32_t number_of_cores_; |
200 size_t max_payload_size_; | 208 size_t max_payload_size_; |
201 | 209 |
202 // The last bitrate/framerate set, and a flag for noting they are set. | 210 // The last bitrate/framerate set, and a flag for noting they are set. |
203 bool rates_set_; | 211 bool rates_set_; |
204 uint32_t bitrate_; | 212 uint32_t bitrate_; |
205 uint32_t framerate_; | 213 uint32_t framerate_; |
206 | 214 |
207 // The last channel parameters set, and a flag for noting they are set. | 215 // The last channel parameters set, and a flag for noting they are set. |
208 bool channel_parameters_set_; | 216 bool channel_parameters_set_; |
209 uint32_t packet_loss_; | 217 uint32_t packet_loss_; |
210 int64_t rtt_; | 218 int64_t rtt_; |
211 | 219 |
212 const EncoderType encoder_type_; | 220 const EncoderType encoder_type_; |
213 webrtc::VideoEncoder* const encoder_; | 221 webrtc::VideoEncoder* const encoder_; |
214 | 222 |
215 std::unique_ptr<webrtc::VideoEncoder> fallback_encoder_; | 223 std::unique_ptr<webrtc::VideoEncoder> fallback_encoder_; |
216 std::string fallback_implementation_name_; | 224 std::string fallback_implementation_name_; |
217 EncodedImageCallback* callback_; | 225 EncodedImageCallback* callback_; |
218 }; | 226 }; |
219 } // namespace webrtc | 227 } // namespace webrtc |
220 #endif // WEBRTC_VIDEO_ENCODER_H_ | 228 #endif // WEBRTC_VIDEO_ENCODER_H_ |
OLD | NEW |