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.
5 #include "media/cast/cast_thread.h"
7 #include "base/logging.h"
9 using base::TaskRunner
;
14 CastThread::CastThread(
15 scoped_refptr
<TaskRunner
> main_thread_proxy
,
16 scoped_refptr
<TaskRunner
> audio_encode_thread_proxy
,
17 scoped_refptr
<TaskRunner
> audio_decode_thread_proxy
,
18 scoped_refptr
<TaskRunner
> video_encode_thread_proxy
,
19 scoped_refptr
<TaskRunner
> video_decode_thread_proxy
)
20 : main_thread_proxy_(main_thread_proxy
),
21 audio_encode_thread_proxy_(audio_encode_thread_proxy
),
22 audio_decode_thread_proxy_(audio_decode_thread_proxy
),
23 video_encode_thread_proxy_(video_encode_thread_proxy
),
24 video_decode_thread_proxy_(video_decode_thread_proxy
) {
25 DCHECK(main_thread_proxy
) << "Main thread required";
28 bool CastThread::PostTask(ThreadId identifier
,
29 const tracked_objects::Location
& from_here
,
30 const base::Closure
& task
) {
31 scoped_refptr
<TaskRunner
> task_runner
=
32 GetMessageTaskRunnerForThread(identifier
);
34 return task_runner
->PostTask(from_here
, task
);
37 bool CastThread::PostDelayedTask(ThreadId identifier
,
38 const tracked_objects::Location
& from_here
,
39 const base::Closure
& task
,
40 base::TimeDelta delay
) {
41 scoped_refptr
<TaskRunner
> task_runner
=
42 GetMessageTaskRunnerForThread(identifier
);
44 return task_runner
->PostDelayedTask(from_here
, task
, delay
);
47 scoped_refptr
<TaskRunner
> CastThread::GetMessageTaskRunnerForThread(
48 ThreadId identifier
) {
50 case CastThread::MAIN
:
51 return main_thread_proxy_
;
52 case CastThread::AUDIO_ENCODER
:
53 return audio_encode_thread_proxy_
;
54 case CastThread::AUDIO_DECODER
:
55 return audio_decode_thread_proxy_
;
56 case CastThread::VIDEO_ENCODER
:
57 return video_encode_thread_proxy_
;
58 case CastThread::VIDEO_DECODER
:
59 return video_decode_thread_proxy_
;