OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/cast/cast_environment.h" | 5 #include "media/cast/cast_environment.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
11 using base::SingleThreadTaskRunner; | 11 using base::SingleThreadTaskRunner; |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 void DeleteLoggingOnMainThread(scoped_ptr<media::cast::LoggingImpl> logging) { | 15 void DeleteLoggingOnMainThread(scoped_ptr<media::cast::LoggingImpl> logging) { |
16 logging.reset(); | 16 logging.reset(); |
17 } | 17 } |
18 | 18 |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 namespace cast { | 22 namespace cast { |
23 | 23 |
24 CastEnvironment::CastEnvironment(scoped_ptr<base::TickClock> clock, | |
25 const CastLoggingConfig& logging_config) | |
26 : clock_(clock.Pass()), logging_(new LoggingImpl(logging_config)) {} | |
27 | |
24 CastEnvironment::CastEnvironment( | 28 CastEnvironment::CastEnvironment( |
25 scoped_ptr<base::TickClock> clock, | 29 scoped_ptr<base::TickClock> clock, |
26 scoped_refptr<SingleThreadTaskRunner> main_thread_proxy, | 30 scoped_refptr<SingleThreadTaskRunner> main_thread_proxy, |
27 scoped_refptr<SingleThreadTaskRunner> audio_encode_thread_proxy, | 31 scoped_refptr<SingleThreadTaskRunner> audio_encode_thread_proxy, |
28 scoped_refptr<SingleThreadTaskRunner> audio_decode_thread_proxy, | 32 scoped_refptr<SingleThreadTaskRunner> audio_decode_thread_proxy, |
29 scoped_refptr<SingleThreadTaskRunner> video_encode_thread_proxy, | 33 scoped_refptr<SingleThreadTaskRunner> video_encode_thread_proxy, |
30 scoped_refptr<SingleThreadTaskRunner> video_decode_thread_proxy, | 34 scoped_refptr<SingleThreadTaskRunner> video_decode_thread_proxy, |
31 scoped_refptr<SingleThreadTaskRunner> transport_thread_proxy, | 35 scoped_refptr<SingleThreadTaskRunner> transport_thread_proxy, |
32 const CastLoggingConfig& config) | 36 const CastLoggingConfig& logging_config) |
33 : clock_(clock.Pass()), | 37 : main_thread_proxy_(main_thread_proxy), |
34 main_thread_proxy_(main_thread_proxy), | |
35 audio_encode_thread_proxy_(audio_encode_thread_proxy), | 38 audio_encode_thread_proxy_(audio_encode_thread_proxy), |
36 audio_decode_thread_proxy_(audio_decode_thread_proxy), | 39 audio_decode_thread_proxy_(audio_decode_thread_proxy), |
37 video_encode_thread_proxy_(video_encode_thread_proxy), | 40 video_encode_thread_proxy_(video_encode_thread_proxy), |
38 video_decode_thread_proxy_(video_decode_thread_proxy), | 41 video_decode_thread_proxy_(video_decode_thread_proxy), |
39 transport_thread_proxy_(transport_thread_proxy), | 42 transport_thread_proxy_(transport_thread_proxy), |
40 logging_(new LoggingImpl(main_thread_proxy, config)) { | 43 clock_(clock.Pass()), |
44 logging_(new LoggingImpl(logging_config)) { | |
41 DCHECK(main_thread_proxy); | 45 DCHECK(main_thread_proxy); |
42 } | 46 } |
43 | 47 |
44 CastEnvironment::~CastEnvironment() { | 48 CastEnvironment::~CastEnvironment() { |
45 // Logging must be deleted on the main thread. | 49 // Logging must be deleted on the main thread. |
46 if (main_thread_proxy_->RunsTasksOnCurrentThread()) { | 50 if (main_thread_proxy_ && !main_thread_proxy_->RunsTasksOnCurrentThread()) { |
47 logging_.reset(); | |
48 } else { | |
49 main_thread_proxy_->PostTask( | 51 main_thread_proxy_->PostTask( |
50 FROM_HERE, | 52 FROM_HERE, |
51 base::Bind(&DeleteLoggingOnMainThread, base::Passed(&logging_))); | 53 base::Bind(&DeleteLoggingOnMainThread, base::Passed(&logging_))); |
52 } | 54 } |
53 } | 55 } |
54 | 56 |
55 bool CastEnvironment::PostTask(ThreadId identifier, | 57 bool CastEnvironment::PostTask(ThreadId identifier, |
56 const tracked_objects::Location& from_here, | 58 const tracked_objects::Location& from_here, |
57 const base::Closure& task) { | 59 const base::Closure& task) { |
58 scoped_refptr<SingleThreadTaskRunner> task_runner = | 60 return GetTaskRunner(identifier)->PostTask(from_here, task); |
59 GetMessageSingleThreadTaskRunnerForThread(identifier); | |
60 | |
61 return task_runner->PostTask(from_here, task); | |
62 } | 61 } |
63 | 62 |
64 bool CastEnvironment::PostDelayedTask( | 63 bool CastEnvironment::PostDelayedTask( |
65 ThreadId identifier, | 64 ThreadId identifier, |
66 const tracked_objects::Location& from_here, | 65 const tracked_objects::Location& from_here, |
67 const base::Closure& task, | 66 const base::Closure& task, |
68 base::TimeDelta delay) { | 67 base::TimeDelta delay) { |
69 scoped_refptr<SingleThreadTaskRunner> task_runner = | 68 return GetTaskRunner(identifier)->PostDelayedTask(from_here, task, delay); |
70 GetMessageSingleThreadTaskRunnerForThread(identifier); | |
71 | |
72 return task_runner->PostDelayedTask(from_here, task, delay); | |
73 } | 69 } |
74 | 70 |
75 scoped_refptr<SingleThreadTaskRunner> | 71 scoped_refptr<SingleThreadTaskRunner> CastEnvironment::GetTaskRunner( |
76 CastEnvironment::GetMessageSingleThreadTaskRunnerForThread( | 72 ThreadId identifier) const { |
77 ThreadId identifier) { | |
78 switch (identifier) { | 73 switch (identifier) { |
79 case CastEnvironment::MAIN: | 74 case CastEnvironment::MAIN: |
80 return main_thread_proxy_; | 75 return main_thread_proxy_; |
81 case CastEnvironment::AUDIO_ENCODER: | 76 case CastEnvironment::AUDIO_ENCODER: |
82 return audio_encode_thread_proxy_; | 77 return audio_encode_thread_proxy_; |
83 case CastEnvironment::AUDIO_DECODER: | 78 case CastEnvironment::AUDIO_DECODER: |
84 return audio_decode_thread_proxy_; | 79 return audio_decode_thread_proxy_; |
85 case CastEnvironment::VIDEO_ENCODER: | 80 case CastEnvironment::VIDEO_ENCODER: |
86 return video_encode_thread_proxy_; | 81 return video_encode_thread_proxy_; |
87 case CastEnvironment::VIDEO_DECODER: | 82 case CastEnvironment::VIDEO_DECODER: |
88 return video_decode_thread_proxy_; | 83 return video_decode_thread_proxy_; |
89 case CastEnvironment::TRANSPORT: | 84 case CastEnvironment::TRANSPORT: |
90 return transport_thread_proxy_; | 85 return transport_thread_proxy_; |
91 default: | 86 default: |
92 NOTREACHED() << "Invalid Thread identifier"; | 87 NOTREACHED() << "Invalid Thread identifier"; |
93 return NULL; | 88 return NULL; |
94 } | 89 } |
95 } | 90 } |
96 | 91 |
97 bool CastEnvironment::CurrentlyOn(ThreadId identifier) { | 92 bool CastEnvironment::CurrentlyOn(ThreadId identifier) { |
98 switch (identifier) { | 93 switch (identifier) { |
99 case CastEnvironment::MAIN: | 94 case CastEnvironment::MAIN: |
100 return main_thread_proxy_->RunsTasksOnCurrentThread(); | 95 return main_thread_proxy_ && |
hubbe
2014/03/06 19:54:43
Is this rebase stuff, or did you change this?
If y
miu
2014/03/07 22:40:29
I changed it. Three reasons:
1. The protected co
| |
96 main_thread_proxy_->RunsTasksOnCurrentThread(); | |
101 case CastEnvironment::AUDIO_ENCODER: | 97 case CastEnvironment::AUDIO_ENCODER: |
102 return audio_encode_thread_proxy_->RunsTasksOnCurrentThread(); | 98 return audio_encode_thread_proxy_ && |
99 audio_encode_thread_proxy_->RunsTasksOnCurrentThread(); | |
103 case CastEnvironment::AUDIO_DECODER: | 100 case CastEnvironment::AUDIO_DECODER: |
104 return audio_decode_thread_proxy_->RunsTasksOnCurrentThread(); | 101 return audio_decode_thread_proxy_ && |
102 audio_decode_thread_proxy_->RunsTasksOnCurrentThread(); | |
105 case CastEnvironment::VIDEO_ENCODER: | 103 case CastEnvironment::VIDEO_ENCODER: |
106 return video_encode_thread_proxy_->RunsTasksOnCurrentThread(); | 104 return video_encode_thread_proxy_ && |
105 video_encode_thread_proxy_->RunsTasksOnCurrentThread(); | |
107 case CastEnvironment::VIDEO_DECODER: | 106 case CastEnvironment::VIDEO_DECODER: |
108 return video_decode_thread_proxy_->RunsTasksOnCurrentThread(); | 107 return video_decode_thread_proxy_ && |
108 video_decode_thread_proxy_->RunsTasksOnCurrentThread(); | |
109 case CastEnvironment::TRANSPORT: | 109 case CastEnvironment::TRANSPORT: |
110 return transport_thread_proxy_->RunsTasksOnCurrentThread(); | 110 return transport_thread_proxy_ && |
111 transport_thread_proxy_->RunsTasksOnCurrentThread(); | |
111 default: | 112 default: |
112 NOTREACHED() << "Invalid thread identifier"; | 113 NOTREACHED() << "Invalid thread identifier"; |
113 return false; | 114 return false; |
114 } | 115 } |
115 } | 116 } |
116 | 117 |
117 base::TickClock* CastEnvironment::Clock() const { return clock_.get(); } | |
118 | |
119 LoggingImpl* CastEnvironment::Logging() { | |
120 DCHECK(CurrentlyOn(CastEnvironment::MAIN)) | |
121 << "Must be called from main thread"; | |
122 return logging_.get(); | |
123 } | |
124 | |
125 } // namespace cast | 118 } // namespace cast |
126 } // namespace media | 119 } // namespace media |
OLD | NEW |