aboutsummaryrefslogtreecommitdiff
path: root/webrtc/base/taskrunner.h
diff options
context:
space:
mode:
authorChih-hung Hsieh <chh@google.com>2015-12-01 17:07:48 +0000
committerandroid-build-merger <android-build-merger@google.com>2015-12-01 17:07:48 +0000
commita4acd9d6bc9b3b033d7d274316e75ee067df8d20 (patch)
tree672a185b294789cf991f385c3e395dd63bea9063 /webrtc/base/taskrunner.h
parent3681b90ba4fe7a27232dd3e27897d5d7ed9d651c (diff)
parentfe8b4a657979b49e1701bd92f6d5814a99e0b2be (diff)
downloadwebrtc-a4acd9d6bc9b3b033d7d274316e75ee067df8d20.tar.gz
Merge changes I7bbf776e,I1b827825
am: fe8b4a6579 * commit 'fe8b4a657979b49e1701bd92f6d5814a99e0b2be': (7237 commits) WIP: Changes after merge commit 'cb3f9bd' Make the nonlinear beamformer steerable Utilize bitrate above codec max to protect video. Enable VP9 internal resize by default. Filter overlapping RTP header extensions. Make VCMEncodedFrameCallback const. MediaCodecVideoEncoder: Add number of quality resolution downscales to Encoded callback. Remove redudant encoder rate calls. Create isolate files for nonparallel tests. Register header extensions in RtpRtcpObserver to avoid log spam. Make an enum class out of NetEqDecoder, and hide the neteq_decoders_ table ACM: Move NACK functionality inside NetEq Fix chromium-style warnings in webrtc/sound/. Create a 'webrtc_nonparallel_tests' target. Update scalability structure data according to updates in the RTP payload profile. audio_coding: rename interface -> include Rewrote perform_action_on_all_files to be parallell. Update reference indices according to updates in the RTP payload profile. Disable P2PTransport...TestFailoverControlledSide on Memcheck pass clangcl compile options to ignore warnings in gflags.cc ...
Diffstat (limited to 'webrtc/base/taskrunner.h')
-rw-r--r--webrtc/base/taskrunner.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/webrtc/base/taskrunner.h b/webrtc/base/taskrunner.h
new file mode 100644
index 0000000000..9a43aac068
--- /dev/null
+++ b/webrtc/base/taskrunner.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2004 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_BASE_TASKRUNNER_H__
+#define WEBRTC_BASE_TASKRUNNER_H__
+
+#include <vector>
+
+#include "webrtc/base/basictypes.h"
+#include "webrtc/base/sigslot.h"
+#include "webrtc/base/taskparent.h"
+
+namespace rtc {
+class Task;
+
+const int64_t kSecToMsec = 1000;
+const int64_t kMsecTo100ns = 10000;
+const int64_t kSecTo100ns = kSecToMsec * kMsecTo100ns;
+
+class TaskRunner : public TaskParent, public sigslot::has_slots<> {
+ public:
+ TaskRunner();
+ ~TaskRunner() override;
+
+ virtual void WakeTasks() = 0;
+
+ // Returns the current time in 100ns units. It is used for
+ // determining timeouts. The origin is not important, only
+ // the units and that rollover while the computer is running.
+ //
+ // On Windows, GetSystemTimeAsFileTime is the typical implementation.
+ virtual int64_t CurrentTime() = 0;
+
+ void StartTask(Task *task);
+ void RunTasks();
+ void PollTasks();
+
+ void UpdateTaskTimeout(Task* task, int64_t previous_task_timeout_time);
+
+#ifdef _DEBUG
+ bool is_ok_to_delete(Task* task) {
+ return task == deleting_task_;
+ }
+
+ void IncrementAbortCount() {
+ ++abort_count_;
+ }
+
+ void DecrementAbortCount() {
+ --abort_count_;
+ }
+#endif
+
+ // Returns the next absolute time when a task times out
+ // OR "0" if there is no next timeout.
+ int64_t next_task_timeout() const;
+
+ protected:
+ // The primary usage of this method is to know if
+ // a callback timer needs to be set-up or adjusted.
+ // This method will be called
+ // * when the next_task_timeout() becomes a smaller value OR
+ // * when next_task_timeout() has changed values and the previous
+ // value is in the past.
+ //
+ // If the next_task_timeout moves to the future, this method will *not*
+ // get called (because it subclass should check next_task_timeout()
+ // when its timer goes off up to see if it needs to set-up a new timer).
+ //
+ // Note that this maybe called conservatively. In that it may be
+ // called when no time change has happened.
+ virtual void OnTimeoutChange() {
+ // by default, do nothing.
+ }
+
+ private:
+ void InternalRunTasks(bool in_destructor);
+ void CheckForTimeoutChange(int64_t previous_timeout_time);
+
+ std::vector<Task *> tasks_;
+ Task *next_timeout_task_;
+ bool tasks_running_;
+#ifdef _DEBUG
+ int abort_count_;
+ Task* deleting_task_;
+#endif
+
+ void RecalcNextTimeout(Task *exclude_task);
+};
+
+} // namespace rtc
+
+#endif // TASK_BASE_TASKRUNNER_H__