From dec0b43f15e7486fed7a2720bdc0dad6e2cfaddc Mon Sep 17 00:00:00 2001 From: "pwestin@google.com" Date: Wed, 9 Oct 2013 10:02:15 +0000 Subject: Cleanup how we handle the fake clock. BUG= Review URL: https://codereview.chromium.org/25124002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227712 0039d316-1c4b-4281-b951-d872f2087c98 --- media/cast/cast_environment.cc | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 media/cast/cast_environment.cc (limited to 'media/cast/cast_environment.cc') diff --git a/media/cast/cast_environment.cc b/media/cast/cast_environment.cc new file mode 100644 index 0000000..dddec16 --- /dev/null +++ b/media/cast/cast_environment.cc @@ -0,0 +1,93 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/cast/cast_environment.h" + +#include "base/logging.h" + +using base::TaskRunner; + +namespace media { +namespace cast { + +CastEnvironment::CastEnvironment( + base::TickClock* clock, + scoped_refptr main_thread_proxy, + scoped_refptr audio_encode_thread_proxy, + scoped_refptr audio_decode_thread_proxy, + scoped_refptr video_encode_thread_proxy, + scoped_refptr video_decode_thread_proxy) + : clock_(clock), + main_thread_proxy_(main_thread_proxy), + audio_encode_thread_proxy_(audio_encode_thread_proxy), + audio_decode_thread_proxy_(audio_decode_thread_proxy), + video_encode_thread_proxy_(video_encode_thread_proxy), + video_decode_thread_proxy_(video_decode_thread_proxy) { + DCHECK(main_thread_proxy) << "Main thread required"; +} + +CastEnvironment::~CastEnvironment() {} + +bool CastEnvironment::PostTask(ThreadId identifier, + const tracked_objects::Location& from_here, + const base::Closure& task) { + scoped_refptr task_runner = + GetMessageTaskRunnerForThread(identifier); + + return task_runner->PostTask(from_here, task); +} + +bool CastEnvironment::PostDelayedTask(ThreadId identifier, + const tracked_objects::Location& from_here, + const base::Closure& task, + base::TimeDelta delay) { + scoped_refptr task_runner = + GetMessageTaskRunnerForThread(identifier); + + return task_runner->PostDelayedTask(from_here, task, delay); +} + +scoped_refptr CastEnvironment::GetMessageTaskRunnerForThread( + ThreadId identifier) { + switch (identifier) { + case CastEnvironment::MAIN: + return main_thread_proxy_; + case CastEnvironment::AUDIO_ENCODER: + return audio_encode_thread_proxy_; + case CastEnvironment::AUDIO_DECODER: + return audio_decode_thread_proxy_; + case CastEnvironment::VIDEO_ENCODER: + return video_encode_thread_proxy_; + case CastEnvironment::VIDEO_DECODER: + return video_decode_thread_proxy_; + default: + NOTREACHED() << "Invalid Thread ID."; + return NULL; + } +} + +bool CastEnvironment::CurrentlyOn(ThreadId identifier) { + switch (identifier) { + case CastEnvironment::MAIN: + return main_thread_proxy_->RunsTasksOnCurrentThread(); + case CastEnvironment::AUDIO_ENCODER: + return audio_encode_thread_proxy_->RunsTasksOnCurrentThread(); + case CastEnvironment::AUDIO_DECODER: + return audio_decode_thread_proxy_->RunsTasksOnCurrentThread(); + case CastEnvironment::VIDEO_ENCODER: + return video_encode_thread_proxy_->RunsTasksOnCurrentThread(); + case CastEnvironment::VIDEO_DECODER: + return video_decode_thread_proxy_->RunsTasksOnCurrentThread(); + default: + NOTREACHED() << "Wrong thread identifier"; + return false; + } +} + +base::TickClock* CastEnvironment::Clock() { + return clock_; +} + +} // namespace cast +} // namespace media -- cgit v1.1