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

Side by Side Diff: webrtc/test/fake_encoder.cc

Issue 2573453002: Add multithreaded fake encoder and corresponding FlexFEC VideoSendStreamTest. (Closed)
Patch Set: Fix android. Created 4 years 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/test/fake_encoder.h ('k') | webrtc/video/BUILD.gn » ('j') | 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) 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
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 MultiThreadedFakeH264Encoder::MultiThreadedFakeH264Encoder(Clock* clock)
231 : test::FakeH264Encoder(clock),
232 current_queue_(0),
233 queue1_("Queue 1"),
234 queue2_("Queue 2") {}
235
236 MultiThreadedFakeH264Encoder::~MultiThreadedFakeH264Encoder() = default;
237
238 class MultiThreadedFakeH264Encoder::EncodeTask : public rtc::QueuedTask {
239 public:
240 EncodeTask(MultiThreadedFakeH264Encoder* 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 MultiThreadedFakeH264Encoder* const encoder_;
260 VideoFrame input_image_;
261 CodecSpecificInfo codec_specific_info_;
262 std::vector<FrameType> frame_types_;
263 };
264
265 int32_t MultiThreadedFakeH264Encoder::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(&current_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 MultiThreadedFakeH264Encoder::EncodeCallback(
279 const VideoFrame& input_image,
280 const CodecSpecificInfo* codec_specific_info,
281 const std::vector<FrameType>* frame_types) {
282 return FakeH264Encoder::Encode(input_image, codec_specific_info, frame_types);
283 }
284
228 } // namespace test 285 } // namespace test
229 } // namespace webrtc 286 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/fake_encoder.h ('k') | webrtc/video/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698