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 |
11 #include "webrtc/test/fake_encoder.h" | 11 #include "webrtc/test/fake_encoder.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "webrtc/base/atomicops.h" | |
15 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
16 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 17 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
17 #include "webrtc/system_wrappers/include/sleep.h" | 18 #include "webrtc/system_wrappers/include/sleep.h" |
18 #include "webrtc/test/gtest.h" | 19 #include "webrtc/test/gtest.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 namespace test { | 22 namespace test { |
22 | 23 |
23 FakeEncoder::FakeEncoder(Clock* clock) | 24 FakeEncoder::FakeEncoder(Clock* clock) |
24 : clock_(clock), | 25 : clock_(clock), |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 const CodecSpecificInfo* codec_specific_info, | 219 const CodecSpecificInfo* codec_specific_info, |
219 const std::vector<FrameType>* frame_types) { | 220 const std::vector<FrameType>* frame_types) { |
220 int delay_ms = 0; | 221 int delay_ms = 0; |
221 { | 222 { |
222 rtc::CritScope lock(&lock_); | 223 rtc::CritScope lock(&lock_); |
223 delay_ms = delay_ms_; | 224 delay_ms = delay_ms_; |
224 } | 225 } |
225 SleepMs(delay_ms); | 226 SleepMs(delay_ms); |
226 return FakeEncoder::Encode(input_image, codec_specific_info, frame_types); | 227 return FakeEncoder::Encode(input_image, codec_specific_info, frame_types); |
227 } | 228 } |
229 | |
230 MultiThreadedFakeEncoder::MultiThreadedFakeEncoder(Clock* clock) | |
231 : test::FakeEncoder(clock), | |
232 current_queue_(0), | |
233 queue1_("Queue 1"), | |
234 queue2_("Queue 2") {} | |
235 | |
236 MultiThreadedFakeEncoder::~MultiThreadedFakeEncoder() = default; | |
237 | |
238 class MultiThreadedFakeEncoder::EncodeTask : public rtc::QueuedTask { | |
239 public: | |
240 EncodeTask(MultiThreadedFakeEncoder* encoder, | |
241 const VideoFrame& input_image, | |
242 const CodecSpecificInfo* codec_specific_info, | |
243 const std::vector<FrameType>* frame_types) | |
244 : encoder_(encoder), | |
245 input_image_(input_image), | |
246 codec_specific_info_(), | |
247 frame_types_(*frame_types) { | |
248 if (codec_specific_info) | |
249 codec_specific_info_ = *codec_specific_info; | |
250 } | |
251 | |
252 private: | |
253 bool Run() override { | |
254 encoder_->EncodeCallback(input_image_, &codec_specific_info_, | |
255 &frame_types_); | |
256 return true; | |
257 } | |
258 | |
259 MultiThreadedFakeEncoder* const encoder_; | |
260 VideoFrame input_image_; | |
261 CodecSpecificInfo codec_specific_info_; | |
262 std::vector<FrameType> frame_types_; | |
263 }; | |
264 | |
265 int32_t MultiThreadedFakeEncoder::Encode( | |
266 const VideoFrame& input_image, | |
267 const CodecSpecificInfo* codec_specific_info, | |
268 const std::vector<FrameType>* frame_types) { | |
269 int current_queue = rtc::AtomicOps::Increment(¤t_queue_); | |
270 rtc::TaskQueue& queue = (current_queue % 2 == 0) ? queue1_ : queue2_; | |
271 | |
272 queue.PostTask(std::unique_ptr<rtc::QueuedTask>( | |
273 new EncodeTask(this, input_image, codec_specific_info, frame_types))); | |
274 | |
275 return 0; | |
276 } | |
277 | |
278 int32_t MultiThreadedFakeEncoder::EncodeCallback( | |
279 const VideoFrame& input_image, | |
280 const CodecSpecificInfo* codec_specific_info, | |
281 const std::vector<FrameType>* frame_types) { | |
282 return FakeEncoder::Encode(input_image, codec_specific_info, frame_types); | |
stefan-webrtc
2016/12/12 15:18:28
Doesn't this mean that the encoder will produce tw
brandtr
2016/12/13 11:32:23
Not sure why it would do that?
MultiThreadedFakeE
stefan-webrtc
2016/12/13 13:04:46
Yes, you are right, I misunderstood the code.
| |
283 } | |
284 | |
228 } // namespace test | 285 } // namespace test |
229 } // namespace webrtc | 286 } // namespace webrtc |
OLD | NEW |