OLD | NEW |
| (Empty) |
1 // Copyright 2015 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/base/android/media_codec_player.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/lazy_instance.h" | |
9 #include "base/logging.h" | |
10 | |
11 #define RUN_ON_MEDIA_THREAD(METHOD, ...) \ | |
12 do { \ | |
13 if (!GetMediaTaskRunner()->BelongsToCurrentThread()) { \ | |
14 GetMediaTaskRunner()->PostTask( \ | |
15 FROM_HERE, \ | |
16 base::Bind(&MediaCodecPlayer:: METHOD, weak_this_, ##__VA_ARGS__)); \ | |
17 return; \ | |
18 } \ | |
19 } while(0) | |
20 | |
21 | |
22 namespace media { | |
23 | |
24 class MediaThread : public base::Thread { | |
25 public: | |
26 MediaThread() : base::Thread("BrowserMediaThread") { | |
27 Start(); | |
28 } | |
29 }; | |
30 | |
31 // Create media thread | |
32 base::LazyInstance<MediaThread>::Leaky | |
33 g_media_thread = LAZY_INSTANCE_INITIALIZER; | |
34 | |
35 | |
36 scoped_refptr<base::SingleThreadTaskRunner> GetMediaTaskRunner() { | |
37 return g_media_thread.Pointer()->task_runner(); | |
38 } | |
39 | |
40 // MediaCodecPlayer implementation. | |
41 | |
42 MediaCodecPlayer::MediaCodecPlayer( | |
43 int player_id, | |
44 MediaPlayerManager* manager, | |
45 const RequestMediaResourcesCB& request_media_resources_cb, | |
46 scoped_ptr<DemuxerAndroid> demuxer, | |
47 const GURL& frame_url) | |
48 : MediaPlayerAndroid(player_id, | |
49 manager, | |
50 request_media_resources_cb, | |
51 frame_url), | |
52 ui_task_runner_(base::MessageLoopProxy::current()), | |
53 demuxer_(demuxer.Pass()), | |
54 weak_factory_(this) { | |
55 // UI thread | |
56 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
57 | |
58 DVLOG(1) << "MediaCodecPlayer::MediaCodecPlayer: player_id:" << player_id; | |
59 | |
60 weak_this_ = weak_factory_.GetWeakPtr(); | |
61 | |
62 // Finish initializaton on Media thread | |
63 GetMediaTaskRunner()->PostTask( | |
64 FROM_HERE, base::Bind(&MediaCodecPlayer::Initialize, weak_this_)); | |
65 } | |
66 | |
67 MediaCodecPlayer::~MediaCodecPlayer() | |
68 { | |
69 // Media thread | |
70 DVLOG(1) << "MediaCodecPlayer::~MediaCodecPlayer"; | |
71 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | |
72 } | |
73 | |
74 void MediaCodecPlayer::Initialize() { | |
75 // Media thread | |
76 DVLOG(1) << __FUNCTION__; | |
77 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | |
78 | |
79 demuxer_->Initialize(this); | |
80 } | |
81 | |
82 // MediaPlayerAndroid implementation. | |
83 | |
84 void MediaCodecPlayer::DeleteOnCorrectThread() { | |
85 // UI thread | |
86 DVLOG(1) << __FUNCTION__; | |
87 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
88 | |
89 // The listener-related portion of the base class has to be | |
90 // destroyed on UI thread. | |
91 DestroyListenerOnUIThread(); | |
92 | |
93 // Post deletion onto Media thread | |
94 GetMediaTaskRunner()->DeleteSoon(FROM_HERE, this); | |
95 } | |
96 | |
97 void MediaCodecPlayer::SetVideoSurface(gfx::ScopedJavaSurface surface) { | |
98 RUN_ON_MEDIA_THREAD(SetVideoSurface, base::Passed(&surface)); | |
99 | |
100 // Media thread | |
101 DVLOG(1) << __FUNCTION__; | |
102 | |
103 NOTIMPLEMENTED(); | |
104 } | |
105 | |
106 void MediaCodecPlayer::Start() { | |
107 RUN_ON_MEDIA_THREAD(Start); | |
108 | |
109 // Media thread | |
110 DVLOG(1) << __FUNCTION__; | |
111 | |
112 NOTIMPLEMENTED(); | |
113 } | |
114 | |
115 void MediaCodecPlayer::Pause(bool is_media_related_action) { | |
116 RUN_ON_MEDIA_THREAD(Pause, is_media_related_action); | |
117 | |
118 // Media thread | |
119 DVLOG(1) << __FUNCTION__; | |
120 | |
121 NOTIMPLEMENTED(); | |
122 } | |
123 | |
124 void MediaCodecPlayer::SeekTo(base::TimeDelta timestamp) { | |
125 RUN_ON_MEDIA_THREAD(SeekTo, timestamp); | |
126 | |
127 // Media thread | |
128 DVLOG(1) << __FUNCTION__ << " " << timestamp; | |
129 | |
130 NOTIMPLEMENTED(); | |
131 } | |
132 | |
133 void MediaCodecPlayer::Release() { | |
134 RUN_ON_MEDIA_THREAD(Release); | |
135 | |
136 // Media thread | |
137 DVLOG(1) << __FUNCTION__; | |
138 | |
139 NOTIMPLEMENTED(); | |
140 } | |
141 | |
142 void MediaCodecPlayer::SetVolume(double volume) { | |
143 RUN_ON_MEDIA_THREAD(SetVolume, volume); | |
144 | |
145 // Media thread | |
146 DVLOG(1) << __FUNCTION__ << " " << volume; | |
147 | |
148 NOTIMPLEMENTED(); | |
149 } | |
150 | |
151 int MediaCodecPlayer::GetVideoWidth() { | |
152 // UI thread | |
153 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
154 | |
155 NOTIMPLEMENTED(); | |
156 return 320; | |
157 } | |
158 | |
159 int MediaCodecPlayer::GetVideoHeight() { | |
160 // UI thread | |
161 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
162 | |
163 NOTIMPLEMENTED(); | |
164 return 240; | |
165 } | |
166 | |
167 base::TimeDelta MediaCodecPlayer::GetCurrentTime() { | |
168 // UI thread, Media thread | |
169 NOTIMPLEMENTED(); | |
170 return base::TimeDelta(); | |
171 } | |
172 | |
173 base::TimeDelta MediaCodecPlayer::GetDuration() { | |
174 // UI thread | |
175 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
176 | |
177 NOTIMPLEMENTED(); | |
178 return base::TimeDelta(); | |
179 } | |
180 | |
181 bool MediaCodecPlayer::IsPlaying() { | |
182 // UI thread | |
183 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
184 NOTIMPLEMENTED(); | |
185 return false; | |
186 } | |
187 | |
188 bool MediaCodecPlayer::CanPause() { | |
189 // UI thread | |
190 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
191 NOTIMPLEMENTED(); | |
192 return false; | |
193 } | |
194 | |
195 bool MediaCodecPlayer::CanSeekForward() { | |
196 // UI thread | |
197 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
198 NOTIMPLEMENTED(); | |
199 return false; | |
200 } | |
201 | |
202 bool MediaCodecPlayer::CanSeekBackward() { | |
203 // UI thread | |
204 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
205 NOTIMPLEMENTED(); | |
206 return false; | |
207 } | |
208 | |
209 bool MediaCodecPlayer::IsPlayerReady() { | |
210 // UI thread | |
211 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
212 NOTIMPLEMENTED(); | |
213 return true; | |
214 } | |
215 | |
216 void MediaCodecPlayer::SetCdm(BrowserCdm* cdm) { | |
217 // UI thread | |
218 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
219 NOTIMPLEMENTED(); | |
220 } | |
221 | |
222 // Callbacks from Demuxer. | |
223 | |
224 void MediaCodecPlayer::OnDemuxerConfigsAvailable( | |
225 const DemuxerConfigs& configs) { | |
226 // Media thread | |
227 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | |
228 | |
229 NOTIMPLEMENTED(); | |
230 } | |
231 | |
232 void MediaCodecPlayer::OnDemuxerDataAvailable(const DemuxerData& data) { | |
233 // Media thread | |
234 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | |
235 NOTIMPLEMENTED(); | |
236 } | |
237 | |
238 void MediaCodecPlayer::OnDemuxerSeekDone( | |
239 base::TimeDelta actual_browser_seek_time) { | |
240 // Media thread | |
241 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | |
242 NOTIMPLEMENTED(); | |
243 } | |
244 | |
245 void MediaCodecPlayer::OnDemuxerDurationChanged( | |
246 base::TimeDelta duration) { | |
247 // Media thread | |
248 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | |
249 NOTIMPLEMENTED(); | |
250 } | |
251 | |
252 } // namespace media | |
OLD | NEW |