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

Unified Diff: webrtc/test/frame_generator_capturer.cc

Issue 2745583006: Reland of rewrite frame generator capturer to use TaskQueue instead of EventTimeWrapper (Closed)
Patch Set: Make overuse in CallPerfTest more reliable Created 3 years, 9 months 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
« no previous file with comments | « webrtc/test/frame_generator_capturer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/test/frame_generator_capturer.cc
diff --git a/webrtc/test/frame_generator_capturer.cc b/webrtc/test/frame_generator_capturer.cc
index 00efbc8b40b467e2248169349ac498997b8de3d2..0b2f1d64bdf49dbfbed487fefdc65622193d2b6a 100644
--- a/webrtc/test/frame_generator_capturer.cc
+++ b/webrtc/test/frame_generator_capturer.cc
@@ -10,10 +10,13 @@
#include "webrtc/test/frame_generator_capturer.h"
+#include <utility>
+#include <vector>
+
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/platform_thread.h"
+#include "webrtc/base/task_queue.h"
#include "webrtc/system_wrappers/include/clock.h"
-#include "webrtc/system_wrappers/include/event_wrapper.h"
#include "webrtc/system_wrappers/include/sleep.h"
#include "webrtc/test/frame_generator.h"
#include "webrtc/video_send_stream.h"
@@ -21,6 +24,31 @@
namespace webrtc {
namespace test {
+class FrameGeneratorCapturer::InsertFrameTask : public rtc::QueuedTask {
+ public:
+ // Repeats in |repeat_interval_ms|. One-time if |repeat_interval_ms| == 0.
+ InsertFrameTask(
+ webrtc::test::FrameGeneratorCapturer* frame_generator_capturer,
+ uint32_t repeat_interval_ms)
+ : frame_generator_capturer_(frame_generator_capturer),
+ repeat_interval_ms_(repeat_interval_ms) {}
+
+ private:
+ bool Run() override {
+ if (repeat_interval_ms_ > 0) {
+ rtc::TaskQueue::Current()->PostDelayedTask(
+ std::unique_ptr<rtc::QueuedTask>(this),
+ repeat_interval_ms_);
+ }
+ frame_generator_capturer_->InsertFrame();
+ // Task should be deleted only if it's not repeating.
+ return repeat_interval_ms_ == 0;
+ }
+
+ webrtc::test::FrameGeneratorCapturer* const frame_generator_capturer_;
tommi 2017/03/10 17:30:01 There's a race related to using this pointer since
ilnik 2017/03/10 17:44:06 But the task queue in question is the member of th
+ const uint32_t repeat_interval_ms_;
+};
+
FrameGeneratorCapturer* FrameGeneratorCapturer::Create(int width,
int height,
int target_fps,
@@ -61,8 +89,7 @@ FrameGeneratorCapturer::FrameGeneratorCapturer(
sending_(false),
sink_(nullptr),
sink_wants_observer_(nullptr),
- tick_(EventTimerWrapper::Create()),
- thread_(FrameGeneratorCapturer::Run, this, "FrameGeneratorCapturer"),
+ task_queue_("FrameGeneratorQueue", rtc::TaskQueue::Priority::HIGH),
frame_generator_(std::move(frame_generator)),
target_fps_(target_fps),
first_frame_capture_time_(-1) {
@@ -72,8 +99,6 @@ FrameGeneratorCapturer::FrameGeneratorCapturer(
FrameGeneratorCapturer::~FrameGeneratorCapturer() {
Stop();
-
- thread_.Stop();
}
void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) {
@@ -87,15 +112,11 @@ bool FrameGeneratorCapturer::Init() {
if (frame_generator_.get() == NULL)
return false;
- if (!tick_->StartTimer(true, 1000 / target_fps_))
- return false;
- thread_.Start();
- thread_.SetPriority(rtc::kHighPriority);
- return true;
-}
+ task_queue_.PostDelayedTask(
+ std::unique_ptr<rtc::QueuedTask>(
+ new InsertFrameTask(this, 1000 / target_fps_)),
+ 1000 / target_fps_);
-bool FrameGeneratorCapturer::Run(void* obj) {
- static_cast<FrameGeneratorCapturer*>(obj)->InsertFrame();
return true;
}
@@ -113,7 +134,6 @@ void FrameGeneratorCapturer::InsertFrame() {
sink_->OnFrame(*frame);
}
}
- tick_->Wait(WEBRTC_EVENT_INFINITE);
}
void FrameGeneratorCapturer::Start() {
@@ -155,7 +175,11 @@ void FrameGeneratorCapturer::RemoveSink(
}
void FrameGeneratorCapturer::ForceFrame() {
- tick_->Set();
+ // One-time non-repeating task,
+ // therefore repeat_interval_ms is 0 in InsertFrameTask()
+ task_queue_.PostTask(
+ std::unique_ptr<rtc::QueuedTask>(new InsertFrameTask(this, 0)));
}
-} // test
-} // webrtc
+
+} // namespace test
+} // namespace webrtc
« no previous file with comments | « webrtc/test/frame_generator_capturer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698