cast_environment.cc revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "media/cast/cast_environment.h" 6 7#include "base/logging.h" 8 9using base::TaskRunner; 10 11namespace media { 12namespace cast { 13 14CastEnvironment::CastEnvironment( 15 base::TickClock* clock, 16 scoped_refptr<TaskRunner> main_thread_proxy, 17 scoped_refptr<TaskRunner> audio_encode_thread_proxy, 18 scoped_refptr<TaskRunner> audio_decode_thread_proxy, 19 scoped_refptr<TaskRunner> video_encode_thread_proxy, 20 scoped_refptr<TaskRunner> video_decode_thread_proxy) 21 : clock_(clock), 22 main_thread_proxy_(main_thread_proxy), 23 audio_encode_thread_proxy_(audio_encode_thread_proxy), 24 audio_decode_thread_proxy_(audio_decode_thread_proxy), 25 video_encode_thread_proxy_(video_encode_thread_proxy), 26 video_decode_thread_proxy_(video_decode_thread_proxy) { 27 DCHECK(main_thread_proxy) << "Main thread required"; 28} 29 30CastEnvironment::~CastEnvironment() {} 31 32bool CastEnvironment::PostTask(ThreadId identifier, 33 const tracked_objects::Location& from_here, 34 const base::Closure& task) { 35 scoped_refptr<TaskRunner> task_runner = 36 GetMessageTaskRunnerForThread(identifier); 37 38 return task_runner->PostTask(from_here, task); 39} 40 41bool CastEnvironment::PostDelayedTask(ThreadId identifier, 42 const tracked_objects::Location& from_here, 43 const base::Closure& task, 44 base::TimeDelta delay) { 45 scoped_refptr<TaskRunner> task_runner = 46 GetMessageTaskRunnerForThread(identifier); 47 48 return task_runner->PostDelayedTask(from_here, task, delay); 49} 50 51scoped_refptr<TaskRunner> CastEnvironment::GetMessageTaskRunnerForThread( 52 ThreadId identifier) { 53 switch (identifier) { 54 case CastEnvironment::MAIN: 55 return main_thread_proxy_; 56 case CastEnvironment::AUDIO_ENCODER: 57 return audio_encode_thread_proxy_; 58 case CastEnvironment::AUDIO_DECODER: 59 return audio_decode_thread_proxy_; 60 case CastEnvironment::VIDEO_ENCODER: 61 return video_encode_thread_proxy_; 62 case CastEnvironment::VIDEO_DECODER: 63 return video_decode_thread_proxy_; 64 default: 65 NOTREACHED() << "Invalid Thread ID."; 66 return NULL; 67 } 68} 69 70bool CastEnvironment::CurrentlyOn(ThreadId identifier) { 71 switch (identifier) { 72 case CastEnvironment::MAIN: 73 return main_thread_proxy_->RunsTasksOnCurrentThread(); 74 case CastEnvironment::AUDIO_ENCODER: 75 return audio_encode_thread_proxy_->RunsTasksOnCurrentThread(); 76 case CastEnvironment::AUDIO_DECODER: 77 return audio_decode_thread_proxy_->RunsTasksOnCurrentThread(); 78 case CastEnvironment::VIDEO_ENCODER: 79 return video_encode_thread_proxy_->RunsTasksOnCurrentThread(); 80 case CastEnvironment::VIDEO_DECODER: 81 return video_decode_thread_proxy_->RunsTasksOnCurrentThread(); 82 default: 83 NOTREACHED() << "Wrong thread identifier"; 84 return false; 85 } 86} 87 88base::TickClock* CastEnvironment::Clock() { 89 return clock_; 90} 91 92} // namespace cast 93} // namespace media 94