OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 DelayedEncoder::DelayedEncoder(Clock* clock, int delay_ms) | 196 DelayedEncoder::DelayedEncoder(Clock* clock, int delay_ms) |
197 : test::FakeEncoder(clock), | 197 : test::FakeEncoder(clock), |
198 delay_ms_(delay_ms) {} | 198 delay_ms_(delay_ms) {} |
199 | 199 |
200 int32_t DelayedEncoder::Encode(const VideoFrame& input_image, | 200 int32_t DelayedEncoder::Encode(const VideoFrame& input_image, |
201 const CodecSpecificInfo* codec_specific_info, | 201 const CodecSpecificInfo* codec_specific_info, |
202 const std::vector<FrameType>* frame_types) { | 202 const std::vector<FrameType>* frame_types) { |
203 SleepMs(delay_ms_); | 203 SleepMs(delay_ms_); |
204 return FakeEncoder::Encode(input_image, codec_specific_info, frame_types); | 204 return FakeEncoder::Encode(input_image, codec_specific_info, frame_types); |
205 } | 205 } |
| 206 |
| 207 InternalSourceEncoder::InternalSourceEncoder(Clock* clock, |
| 208 uint32_t frame_period_ms, |
| 209 uint32_t first_frame_timestamp_ms) |
| 210 : test::FakeEncoder(clock), |
| 211 thread_(EncoderProcess, this, "InternalSourceEncoderProcess"), |
| 212 frame_period_ms_(frame_period_ms), |
| 213 current_frame_timestamp_ms_(first_frame_timestamp_ms), |
| 214 shutting_down_(false), |
| 215 next_frame_type_(kVideoFrameKey) {} |
| 216 |
| 217 int32_t InternalSourceEncoder::InitEncode(const VideoCodec* config, |
| 218 int32_t number_of_cores, |
| 219 size_t max_payload_size) { |
| 220 int32_t result = |
| 221 test::FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
| 222 thread_.Start(); |
| 223 return result; |
| 224 } |
| 225 |
| 226 bool InternalSourceEncoder::EncoderProcess(void* encoder_void_ptr) { |
| 227 InternalSourceEncoder* encoder = |
| 228 static_cast<InternalSourceEncoder*>(encoder_void_ptr); |
| 229 SleepMs(encoder->frame_period_ms_); |
| 230 return encoder->EncodeFrame(); |
| 231 } |
| 232 |
| 233 bool InternalSourceEncoder::EncodeFrame() { |
| 234 FrameType frame_type; |
| 235 { |
| 236 rtc::CritScope crit(&lock_); |
| 237 if (shutting_down_) { |
| 238 return false; |
| 239 } |
| 240 frame_type = next_frame_type_; |
| 241 // Reset the frame type, now that we've consumed a keyframe request (if it |
| 242 // was kVideoFrameKey). |
| 243 next_frame_type_ = kVideoFrameDelta; |
| 244 } |
| 245 VideoFrame input_image(rtc::scoped_refptr<webrtc::VideoFrameBuffer>(), |
| 246 current_frame_timestamp_ms_ * 90, |
| 247 current_frame_timestamp_ms_, kVideoRotation_0); |
| 248 current_frame_timestamp_ms_ += frame_period_ms_; |
| 249 std::vector<FrameType> frame_types{frame_type}; |
| 250 |
| 251 // Call the base class explicitly, to skip our no-op override. |
| 252 test::FakeEncoder::Encode(input_image, nullptr, &frame_types); |
| 253 return true; |
| 254 } |
| 255 |
| 256 int32_t InternalSourceEncoder::Release() { |
| 257 { |
| 258 rtc::CritScope crit(&lock_); |
| 259 shutting_down_ = true; |
| 260 } |
| 261 thread_.Stop(); |
| 262 return test::FakeEncoder::Release(); |
| 263 } |
| 264 |
| 265 int32_t InternalSourceEncoder::Encode( |
| 266 const VideoFrame& input_image, |
| 267 const CodecSpecificInfo* codec_specific_info, |
| 268 const std::vector<FrameType>* frame_types) { |
| 269 // Check for keyframe requests. |
| 270 if (frame_types) { |
| 271 for (FrameType type : *frame_types) { |
| 272 if (type == kVideoFrameKey) { |
| 273 rtc::CritScope crit(&lock_); |
| 274 next_frame_type_ = kVideoFrameKey; |
| 275 break; |
| 276 } |
| 277 } |
| 278 } |
| 279 return WEBRTC_VIDEO_CODEC_OK; |
| 280 } |
| 281 |
206 } // namespace test | 282 } // namespace test |
207 } // namespace webrtc | 283 } // namespace webrtc |
OLD | NEW |