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

Unified Diff: webrtc/test/fake_encoder.cc

Issue 2573453002: Add multithreaded fake encoder and corresponding FlexFEC VideoSendStreamTest. (Closed)
Patch Set: Add the test here. 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/test/fake_encoder.cc
diff --git a/webrtc/test/fake_encoder.cc b/webrtc/test/fake_encoder.cc
index ae1788bf6c6e534c885a0b9db0338fd0e85e5a24..584d02bd3254ff5d4ea15b2f3930de6255420adc 100644
--- a/webrtc/test/fake_encoder.cc
+++ b/webrtc/test/fake_encoder.cc
@@ -12,6 +12,7 @@
#include <algorithm>
+#include "webrtc/base/atomicops.h"
#include "webrtc/base/checks.h"
#include "webrtc/modules/video_coding/include/video_codec_interface.h"
#include "webrtc/system_wrappers/include/sleep.h"
@@ -225,5 +226,61 @@ int32_t DelayedEncoder::Encode(const VideoFrame& input_image,
SleepMs(delay_ms);
return FakeEncoder::Encode(input_image, codec_specific_info, frame_types);
}
+
+MultiThreadedFakeEncoder::MultiThreadedFakeEncoder(Clock* clock)
+ : test::FakeEncoder(clock),
+ current_queue_(0),
+ queue1_("Queue 1"),
+ queue2_("Queue 2") {}
+
+MultiThreadedFakeEncoder::~MultiThreadedFakeEncoder() = default;
+
+class MultiThreadedFakeEncoder::EncodeTask : public rtc::QueuedTask {
+ public:
+ EncodeTask(MultiThreadedFakeEncoder* encoder,
+ const VideoFrame& input_image,
+ const CodecSpecificInfo* codec_specific_info,
+ const std::vector<FrameType>* frame_types)
+ : encoder_(encoder),
+ input_image_(input_image),
+ codec_specific_info_(),
+ frame_types_(*frame_types) {
+ if (codec_specific_info)
+ codec_specific_info_ = *codec_specific_info;
+ }
+
+ private:
+ bool Run() override {
+ encoder_->EncodeCallback(input_image_, &codec_specific_info_,
+ &frame_types_);
+ return true;
+ }
+
+ MultiThreadedFakeEncoder* const encoder_;
+ VideoFrame input_image_;
+ CodecSpecificInfo codec_specific_info_;
+ std::vector<FrameType> frame_types_;
+};
+
+int32_t MultiThreadedFakeEncoder::Encode(
+ const VideoFrame& input_image,
+ const CodecSpecificInfo* codec_specific_info,
+ const std::vector<FrameType>* frame_types) {
+ int current_queue = rtc::AtomicOps::Increment(&current_queue_);
+ rtc::TaskQueue& queue = (current_queue % 2 == 0) ? queue1_ : queue2_;
+
+ queue.PostTask(std::unique_ptr<rtc::QueuedTask>(
+ new EncodeTask(this, input_image, codec_specific_info, frame_types)));
+
+ return 0;
+}
+
+int32_t MultiThreadedFakeEncoder::EncodeCallback(
+ const VideoFrame& input_image,
+ const CodecSpecificInfo* codec_specific_info,
+ const std::vector<FrameType>* frame_types) {
+ 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.
+}
+
} // namespace test
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698