OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/base/android/media_source_player.h" | 5 #include "media/base/android/legacy_media_source_player.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
11 #include "base/barrier_closure.h" | 11 #include "base/barrier_closure.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
18 #include "media/base/android/audio_decoder_job.h" | 18 #include "media/base/android/audio_decoder_job.h" |
19 #include "media/base/android/media_drm_bridge.h" | 19 #include "media/base/android/media_drm_bridge.h" |
20 #include "media/base/android/media_player_manager.h" | 20 #include "media/base/android/media_player_manager.h" |
21 #include "media/base/android/video_decoder_job.h" | 21 #include "media/base/android/video_decoder_job.h" |
22 | 22 |
23 namespace media { | 23 namespace media { |
24 | 24 |
25 MediaSourcePlayer::MediaSourcePlayer( | 25 LegacyMediaSourcePlayer::LegacyMediaSourcePlayer( |
26 int player_id, | 26 int player_id, |
27 MediaPlayerManager* manager, | 27 MediaPlayerManager* manager, |
28 const RequestMediaResourcesCB& request_media_resources_cb, | 28 const RequestMediaResourcesCB& request_media_resources_cb, |
29 scoped_ptr<DemuxerAndroid> demuxer, | 29 scoped_ptr<DemuxerAndroid> demuxer, |
30 const GURL& frame_url) | 30 const GURL& frame_url) |
31 : MediaPlayerAndroid(player_id, | 31 : MediaPlayerAndroid(player_id, |
32 manager, | 32 manager, |
33 request_media_resources_cb, | 33 request_media_resources_cb, |
34 frame_url), | 34 frame_url), |
35 demuxer_(demuxer.Pass()), | 35 demuxer_(demuxer.Pass()), |
36 pending_event_(NO_EVENT_PENDING), | 36 pending_event_(NO_EVENT_PENDING), |
37 playing_(false), | 37 playing_(false), |
38 interpolator_(&default_tick_clock_), | 38 interpolator_(&default_tick_clock_), |
39 doing_browser_seek_(false), | 39 doing_browser_seek_(false), |
40 pending_seek_(false), | 40 pending_seek_(false), |
41 drm_bridge_(NULL), | 41 drm_bridge_(NULL), |
42 cdm_registration_id_(0), | 42 cdm_registration_id_(0), |
43 is_waiting_for_key_(false), | 43 is_waiting_for_key_(false), |
44 key_added_while_decode_pending_(false), | 44 key_added_while_decode_pending_(false), |
45 is_waiting_for_audio_decoder_(false), | 45 is_waiting_for_audio_decoder_(false), |
46 is_waiting_for_video_decoder_(false), | 46 is_waiting_for_video_decoder_(false), |
47 prerolling_(true), | 47 prerolling_(true), |
48 weak_factory_(this) { | 48 weak_factory_(this) { |
49 audio_decoder_job_.reset(new AudioDecoderJob( | 49 audio_decoder_job_.reset(new AudioDecoderJob( |
50 base::Bind(&DemuxerAndroid::RequestDemuxerData, | 50 base::Bind(&DemuxerAndroid::RequestDemuxerData, |
51 base::Unretained(demuxer_.get()), | 51 base::Unretained(demuxer_.get()), |
52 DemuxerStream::AUDIO), | 52 DemuxerStream::AUDIO), |
53 base::Bind(&MediaSourcePlayer::OnDemuxerConfigsChanged, | 53 base::Bind(&LegacyMediaSourcePlayer::OnDemuxerConfigsChanged, |
54 weak_factory_.GetWeakPtr()))); | 54 weak_factory_.GetWeakPtr()))); |
55 video_decoder_job_.reset(new VideoDecoderJob( | 55 video_decoder_job_.reset(new VideoDecoderJob( |
56 base::Bind(&DemuxerAndroid::RequestDemuxerData, | 56 base::Bind(&DemuxerAndroid::RequestDemuxerData, |
57 base::Unretained(demuxer_.get()), | 57 base::Unretained(demuxer_.get()), |
58 DemuxerStream::VIDEO), | 58 DemuxerStream::VIDEO), |
59 base::Bind(request_media_resources_cb_, player_id), | 59 base::Bind(request_media_resources_cb_, player_id), |
60 base::Bind(&MediaSourcePlayer::OnDemuxerConfigsChanged, | 60 base::Bind(&LegacyMediaSourcePlayer::OnDemuxerConfigsChanged, |
61 weak_factory_.GetWeakPtr()))); | 61 weak_factory_.GetWeakPtr()))); |
62 demuxer_->Initialize(this); | 62 demuxer_->Initialize(this); |
63 interpolator_.SetUpperBound(base::TimeDelta()); | 63 interpolator_.SetUpperBound(base::TimeDelta()); |
64 weak_this_ = weak_factory_.GetWeakPtr(); | 64 weak_this_ = weak_factory_.GetWeakPtr(); |
65 } | 65 } |
66 | 66 |
67 MediaSourcePlayer::~MediaSourcePlayer() { | 67 LegacyMediaSourcePlayer::~LegacyMediaSourcePlayer() { |
68 Release(); | 68 Release(); |
69 DCHECK_EQ(!drm_bridge_, !cdm_registration_id_); | 69 DCHECK_EQ(!drm_bridge_, !cdm_registration_id_); |
70 if (drm_bridge_) { | 70 if (drm_bridge_) { |
71 drm_bridge_->UnregisterPlayer(cdm_registration_id_); | 71 drm_bridge_->UnregisterPlayer(cdm_registration_id_); |
72 cdm_registration_id_ = 0; | 72 cdm_registration_id_ = 0; |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 void MediaSourcePlayer::SetVideoSurface(gfx::ScopedJavaSurface surface) { | 76 void LegacyMediaSourcePlayer::SetVideoSurface(gfx::ScopedJavaSurface surface) { |
77 DVLOG(1) << __FUNCTION__; | 77 DVLOG(1) << __FUNCTION__; |
78 if (!video_decoder_job_->SetVideoSurface(surface.Pass())) | 78 if (!video_decoder_job_->SetVideoSurface(surface.Pass())) |
79 return; | 79 return; |
80 // Retry video decoder creation. | 80 // Retry video decoder creation. |
81 RetryDecoderCreation(false, true); | 81 RetryDecoderCreation(false, true); |
82 } | 82 } |
83 | 83 |
84 void MediaSourcePlayer::ScheduleSeekEventAndStopDecoding( | 84 void LegacyMediaSourcePlayer::ScheduleSeekEventAndStopDecoding( |
85 base::TimeDelta seek_time) { | 85 base::TimeDelta seek_time) { |
86 DVLOG(1) << __FUNCTION__ << "(" << seek_time.InSecondsF() << ")"; | 86 DVLOG(1) << __FUNCTION__ << "(" << seek_time.InSecondsF() << ")"; |
87 DCHECK(!IsEventPending(SEEK_EVENT_PENDING)); | 87 DCHECK(!IsEventPending(SEEK_EVENT_PENDING)); |
88 | 88 |
89 pending_seek_ = false; | 89 pending_seek_ = false; |
90 | 90 |
91 interpolator_.SetBounds(seek_time, seek_time); | 91 interpolator_.SetBounds(seek_time, seek_time); |
92 | 92 |
93 if (audio_decoder_job_->is_decoding()) | 93 if (audio_decoder_job_->is_decoding()) |
94 audio_decoder_job_->StopDecode(); | 94 audio_decoder_job_->StopDecode(); |
95 if (video_decoder_job_->is_decoding()) | 95 if (video_decoder_job_->is_decoding()) |
96 video_decoder_job_->StopDecode(); | 96 video_decoder_job_->StopDecode(); |
97 | 97 |
98 SetPendingEvent(SEEK_EVENT_PENDING); | 98 SetPendingEvent(SEEK_EVENT_PENDING); |
99 ProcessPendingEvents(); | 99 ProcessPendingEvents(); |
100 } | 100 } |
101 | 101 |
102 void MediaSourcePlayer::BrowserSeekToCurrentTime() { | 102 void LegacyMediaSourcePlayer::BrowserSeekToCurrentTime() { |
103 DVLOG(1) << __FUNCTION__; | 103 DVLOG(1) << __FUNCTION__; |
104 | 104 |
105 DCHECK(!IsEventPending(SEEK_EVENT_PENDING)); | 105 DCHECK(!IsEventPending(SEEK_EVENT_PENDING)); |
106 doing_browser_seek_ = true; | 106 doing_browser_seek_ = true; |
107 ScheduleSeekEventAndStopDecoding(GetCurrentTime()); | 107 ScheduleSeekEventAndStopDecoding(GetCurrentTime()); |
108 } | 108 } |
109 | 109 |
110 bool MediaSourcePlayer::Seekable() { | 110 bool LegacyMediaSourcePlayer::Seekable() { |
111 // If the duration TimeDelta, converted to milliseconds from microseconds, | 111 // If the duration TimeDelta, converted to milliseconds from microseconds, |
112 // is >= 2^31, then the media is assumed to be unbounded and unseekable. | 112 // is >= 2^31, then the media is assumed to be unbounded and unseekable. |
113 // 2^31 is the bound due to java player using 32-bit integer for time | 113 // 2^31 is the bound due to java player using 32-bit integer for time |
114 // values at millisecond resolution. | 114 // values at millisecond resolution. |
115 return duration_ < | 115 return duration_ < |
116 base::TimeDelta::FromMilliseconds(std::numeric_limits<int32>::max()); | 116 base::TimeDelta::FromMilliseconds(std::numeric_limits<int32>::max()); |
117 } | 117 } |
118 | 118 |
119 void MediaSourcePlayer::Start() { | 119 void LegacyMediaSourcePlayer::Start() { |
120 DVLOG(1) << __FUNCTION__; | 120 DVLOG(1) << __FUNCTION__; |
121 | 121 |
122 playing_ = true; | 122 playing_ = true; |
123 | 123 |
124 StartInternal(); | 124 StartInternal(); |
125 } | 125 } |
126 | 126 |
127 void MediaSourcePlayer::Pause(bool is_media_related_action) { | 127 void LegacyMediaSourcePlayer::Pause(bool is_media_related_action) { |
128 DVLOG(1) << __FUNCTION__; | 128 DVLOG(1) << __FUNCTION__; |
129 | 129 |
130 // Since decoder jobs have their own thread, decoding is not fully paused | 130 // Since decoder jobs have their own thread, decoding is not fully paused |
131 // until all the decoder jobs call MediaDecoderCallback(). It is possible | 131 // until all the decoder jobs call MediaDecoderCallback(). It is possible |
132 // that Start() is called while the player is waiting for | 132 // that Start() is called while the player is waiting for |
133 // MediaDecoderCallback(). In that case, decoding will continue when | 133 // MediaDecoderCallback(). In that case, decoding will continue when |
134 // MediaDecoderCallback() is called. | 134 // MediaDecoderCallback() is called. |
135 playing_ = false; | 135 playing_ = false; |
136 start_time_ticks_ = base::TimeTicks(); | 136 start_time_ticks_ = base::TimeTicks(); |
137 } | 137 } |
138 | 138 |
139 bool MediaSourcePlayer::IsPlaying() { | 139 bool LegacyMediaSourcePlayer::IsPlaying() { |
140 return playing_; | 140 return playing_; |
141 } | 141 } |
142 | 142 |
143 int MediaSourcePlayer::GetVideoWidth() { | 143 int LegacyMediaSourcePlayer::GetVideoWidth() { |
144 return video_decoder_job_->output_width(); | 144 return video_decoder_job_->output_width(); |
145 } | 145 } |
146 | 146 |
147 int MediaSourcePlayer::GetVideoHeight() { | 147 int LegacyMediaSourcePlayer::GetVideoHeight() { |
148 return video_decoder_job_->output_height(); | 148 return video_decoder_job_->output_height(); |
149 } | 149 } |
150 | 150 |
151 void MediaSourcePlayer::SeekTo(base::TimeDelta timestamp) { | 151 void LegacyMediaSourcePlayer::SeekTo(base::TimeDelta timestamp) { |
152 DVLOG(1) << __FUNCTION__ << "(" << timestamp.InSecondsF() << ")"; | 152 DVLOG(1) << __FUNCTION__ << "(" << timestamp.InSecondsF() << ")"; |
153 | 153 |
154 if (IsEventPending(SEEK_EVENT_PENDING)) { | 154 if (IsEventPending(SEEK_EVENT_PENDING)) { |
155 DCHECK(doing_browser_seek_) << "SeekTo while SeekTo in progress"; | 155 DCHECK(doing_browser_seek_) << "SeekTo while SeekTo in progress"; |
156 DCHECK(!pending_seek_) << "SeekTo while SeekTo pending browser seek"; | 156 DCHECK(!pending_seek_) << "SeekTo while SeekTo pending browser seek"; |
157 | 157 |
158 // There is a browser seek currently in progress to obtain I-frame to feed | 158 // There is a browser seek currently in progress to obtain I-frame to feed |
159 // a newly constructed video decoder. Remember this real seek request so | 159 // a newly constructed video decoder. Remember this real seek request so |
160 // it can be initiated once OnDemuxerSeekDone() occurs for the browser seek. | 160 // it can be initiated once OnDemuxerSeekDone() occurs for the browser seek. |
161 pending_seek_ = true; | 161 pending_seek_ = true; |
162 pending_seek_time_ = timestamp; | 162 pending_seek_time_ = timestamp; |
163 return; | 163 return; |
164 } | 164 } |
165 | 165 |
166 doing_browser_seek_ = false; | 166 doing_browser_seek_ = false; |
167 ScheduleSeekEventAndStopDecoding(timestamp); | 167 ScheduleSeekEventAndStopDecoding(timestamp); |
168 } | 168 } |
169 | 169 |
170 base::TimeDelta MediaSourcePlayer::GetCurrentTime() { | 170 base::TimeDelta LegacyMediaSourcePlayer::GetCurrentTime() { |
171 return std::min(interpolator_.GetInterpolatedTime(), duration_); | 171 return std::min(interpolator_.GetInterpolatedTime(), duration_); |
172 } | 172 } |
173 | 173 |
174 base::TimeDelta MediaSourcePlayer::GetDuration() { | 174 base::TimeDelta LegacyMediaSourcePlayer::GetDuration() { |
175 return duration_; | 175 return duration_; |
176 } | 176 } |
177 | 177 |
178 void MediaSourcePlayer::Release() { | 178 void LegacyMediaSourcePlayer::Release() { |
179 DVLOG(1) << __FUNCTION__; | 179 DVLOG(1) << __FUNCTION__; |
180 | 180 |
181 audio_decoder_job_->ReleaseDecoderResources(); | 181 audio_decoder_job_->ReleaseDecoderResources(); |
182 video_decoder_job_->ReleaseDecoderResources(); | 182 video_decoder_job_->ReleaseDecoderResources(); |
183 | 183 |
184 // Prevent player restart, including job re-creation attempts. | 184 // Prevent player restart, including job re-creation attempts. |
185 playing_ = false; | 185 playing_ = false; |
186 | 186 |
187 decoder_starvation_callback_.Cancel(); | 187 decoder_starvation_callback_.Cancel(); |
188 | 188 |
189 SetAudible(false); | 189 SetAudible(false); |
190 DetachListener(); | 190 DetachListener(); |
191 } | 191 } |
192 | 192 |
193 void MediaSourcePlayer::SetVolume(double volume) { | 193 void LegacyMediaSourcePlayer::SetVolume(double volume) { |
194 audio_decoder_job_->SetVolume(volume); | 194 audio_decoder_job_->SetVolume(volume); |
195 } | 195 } |
196 | 196 |
197 bool MediaSourcePlayer::CanPause() { | 197 bool LegacyMediaSourcePlayer::CanPause() { |
198 return Seekable(); | 198 return Seekable(); |
199 } | 199 } |
200 | 200 |
201 bool MediaSourcePlayer::CanSeekForward() { | 201 bool LegacyMediaSourcePlayer::CanSeekForward() { |
202 return Seekable(); | 202 return Seekable(); |
203 } | 203 } |
204 | 204 |
205 bool MediaSourcePlayer::CanSeekBackward() { | 205 bool LegacyMediaSourcePlayer::CanSeekBackward() { |
206 return Seekable(); | 206 return Seekable(); |
207 } | 207 } |
208 | 208 |
209 bool MediaSourcePlayer::IsPlayerReady() { | 209 bool LegacyMediaSourcePlayer::IsPlayerReady() { |
210 return audio_decoder_job_ || video_decoder_job_; | 210 return audio_decoder_job_ || video_decoder_job_; |
211 } | 211 } |
212 | 212 |
213 void MediaSourcePlayer::StartInternal() { | 213 void LegacyMediaSourcePlayer::StartInternal() { |
214 DVLOG(1) << __FUNCTION__; | 214 DVLOG(1) << __FUNCTION__; |
215 // If there are pending events, wait for them finish. | 215 // If there are pending events, wait for them finish. |
216 if (pending_event_ != NO_EVENT_PENDING) | 216 if (pending_event_ != NO_EVENT_PENDING) |
217 return; | 217 return; |
218 | 218 |
219 // When we start, we could have new demuxed data coming in. This new data | 219 // When we start, we could have new demuxed data coming in. This new data |
220 // could be clear (not encrypted) or encrypted with different keys. So key | 220 // could be clear (not encrypted) or encrypted with different keys. So key |
221 // related info should all be cleared. | 221 // related info should all be cleared. |
222 is_waiting_for_key_ = false; | 222 is_waiting_for_key_ = false; |
223 key_added_while_decode_pending_ = false; | 223 key_added_while_decode_pending_ = false; |
224 AttachListener(NULL); | 224 AttachListener(NULL); |
225 | 225 |
226 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); | 226 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); |
227 ProcessPendingEvents(); | 227 ProcessPendingEvents(); |
228 } | 228 } |
229 | 229 |
230 void MediaSourcePlayer::OnDemuxerConfigsAvailable( | 230 void LegacyMediaSourcePlayer::OnDemuxerConfigsAvailable( |
231 const DemuxerConfigs& configs) { | 231 const DemuxerConfigs& configs) { |
232 DVLOG(1) << __FUNCTION__; | 232 DVLOG(1) << __FUNCTION__; |
233 DCHECK(!HasAudio() && !HasVideo()); | 233 DCHECK(!HasAudio() && !HasVideo()); |
234 | 234 |
235 duration_ = configs.duration; | 235 duration_ = configs.duration; |
236 | 236 |
237 audio_decoder_job_->SetDemuxerConfigs(configs); | 237 audio_decoder_job_->SetDemuxerConfigs(configs); |
238 video_decoder_job_->SetDemuxerConfigs(configs); | 238 video_decoder_job_->SetDemuxerConfigs(configs); |
239 OnDemuxerConfigsChanged(); | 239 OnDemuxerConfigsChanged(); |
240 } | 240 } |
241 | 241 |
242 void MediaSourcePlayer::OnDemuxerDataAvailable(const DemuxerData& data) { | 242 void LegacyMediaSourcePlayer::OnDemuxerDataAvailable(const DemuxerData& data) { |
243 DVLOG(1) << __FUNCTION__ << "(" << data.type << ")"; | 243 DVLOG(1) << __FUNCTION__ << "(" << data.type << ")"; |
244 DCHECK_LT(0u, data.access_units.size()); | 244 DCHECK_LT(0u, data.access_units.size()); |
245 CHECK_GE(1u, data.demuxer_configs.size()); | 245 CHECK_GE(1u, data.demuxer_configs.size()); |
246 | 246 |
247 if (data.type == DemuxerStream::AUDIO) | 247 if (data.type == DemuxerStream::AUDIO) |
248 audio_decoder_job_->OnDataReceived(data); | 248 audio_decoder_job_->OnDataReceived(data); |
249 else if (data.type == DemuxerStream::VIDEO) | 249 else if (data.type == DemuxerStream::VIDEO) |
250 video_decoder_job_->OnDataReceived(data); | 250 video_decoder_job_->OnDataReceived(data); |
251 } | 251 } |
252 | 252 |
253 void MediaSourcePlayer::OnDemuxerDurationChanged(base::TimeDelta duration) { | 253 void LegacyMediaSourcePlayer::OnDemuxerDurationChanged( |
| 254 base::TimeDelta duration) { |
254 duration_ = duration; | 255 duration_ = duration; |
255 } | 256 } |
256 | 257 |
257 void MediaSourcePlayer::OnMediaCryptoReady() { | 258 void LegacyMediaSourcePlayer::OnMediaCryptoReady() { |
258 DCHECK(!drm_bridge_->GetMediaCrypto().is_null()); | 259 DCHECK(!drm_bridge_->GetMediaCrypto().is_null()); |
259 drm_bridge_->SetMediaCryptoReadyCB(base::Closure()); | 260 drm_bridge_->SetMediaCryptoReadyCB(base::Closure()); |
260 | 261 |
261 // Retry decoder creation if the decoders are waiting for MediaCrypto. | 262 // Retry decoder creation if the decoders are waiting for MediaCrypto. |
262 RetryDecoderCreation(true, true); | 263 RetryDecoderCreation(true, true); |
263 } | 264 } |
264 | 265 |
265 void MediaSourcePlayer::SetCdm(BrowserCdm* cdm) { | 266 void LegacyMediaSourcePlayer::SetCdm(BrowserCdm* cdm) { |
266 // Currently we don't support DRM change during the middle of playback, even | 267 // Currently we don't support DRM change during the middle of playback, even |
267 // if the player is paused. | 268 // if the player is paused. |
268 // TODO(qinmin): support DRM change after playback has started. | 269 // TODO(qinmin): support DRM change after playback has started. |
269 // http://crbug.com/253792. | 270 // http://crbug.com/253792. |
270 if (GetCurrentTime() > base::TimeDelta()) { | 271 if (GetCurrentTime() > base::TimeDelta()) { |
271 VLOG(0) << "Setting DRM bridge after playback has started. " | 272 VLOG(0) << "Setting DRM bridge after playback has started. " |
272 << "This is not well supported!"; | 273 << "This is not well supported!"; |
273 } | 274 } |
274 | 275 |
275 if (drm_bridge_) { | 276 if (drm_bridge_) { |
276 NOTREACHED() << "Currently we do not support resetting CDM."; | 277 NOTREACHED() << "Currently we do not support resetting CDM."; |
277 return; | 278 return; |
278 } | 279 } |
279 | 280 |
280 // Only MediaDrmBridge will be set on MediaSourcePlayer. | 281 // Only MediaDrmBridge will be set on MediaSourcePlayer. |
281 drm_bridge_ = static_cast<MediaDrmBridge*>(cdm); | 282 drm_bridge_ = static_cast<MediaDrmBridge*>(cdm); |
282 | 283 |
283 cdm_registration_id_ = drm_bridge_->RegisterPlayer( | 284 cdm_registration_id_ = drm_bridge_->RegisterPlayer( |
284 base::Bind(&MediaSourcePlayer::OnKeyAdded, weak_this_), | 285 base::Bind(&LegacyMediaSourcePlayer::OnKeyAdded, weak_this_), |
285 base::Bind(&MediaSourcePlayer::OnCdmUnset, weak_this_)); | 286 base::Bind(&LegacyMediaSourcePlayer::OnCdmUnset, weak_this_)); |
286 | 287 |
287 audio_decoder_job_->SetDrmBridge(drm_bridge_); | 288 audio_decoder_job_->SetDrmBridge(drm_bridge_); |
288 video_decoder_job_->SetDrmBridge(drm_bridge_); | 289 video_decoder_job_->SetDrmBridge(drm_bridge_); |
289 | 290 |
290 if (drm_bridge_->GetMediaCrypto().is_null()) { | 291 if (drm_bridge_->GetMediaCrypto().is_null()) { |
291 drm_bridge_->SetMediaCryptoReadyCB( | 292 drm_bridge_->SetMediaCryptoReadyCB( |
292 base::Bind(&MediaSourcePlayer::OnMediaCryptoReady, weak_this_)); | 293 base::Bind(&LegacyMediaSourcePlayer::OnMediaCryptoReady, weak_this_)); |
293 return; | 294 return; |
294 } | 295 } |
295 | 296 |
296 // If the player is previously waiting for CDM, retry decoder creation. | 297 // If the player is previously waiting for CDM, retry decoder creation. |
297 RetryDecoderCreation(true, true); | 298 RetryDecoderCreation(true, true); |
298 } | 299 } |
299 | 300 |
300 void MediaSourcePlayer::OnDemuxerSeekDone( | 301 void LegacyMediaSourcePlayer::OnDemuxerSeekDone( |
301 base::TimeDelta actual_browser_seek_time) { | 302 base::TimeDelta actual_browser_seek_time) { |
302 DVLOG(1) << __FUNCTION__; | 303 DVLOG(1) << __FUNCTION__; |
303 | 304 |
304 ClearPendingEvent(SEEK_EVENT_PENDING); | 305 ClearPendingEvent(SEEK_EVENT_PENDING); |
305 if (IsEventPending(PREFETCH_REQUEST_EVENT_PENDING)) | 306 if (IsEventPending(PREFETCH_REQUEST_EVENT_PENDING)) |
306 ClearPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); | 307 ClearPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); |
307 | 308 |
308 if (pending_seek_) { | 309 if (pending_seek_) { |
309 DVLOG(1) << __FUNCTION__ << "processing pending seek"; | 310 DVLOG(1) << __FUNCTION__ << "processing pending seek"; |
310 DCHECK(doing_browser_seek_); | 311 DCHECK(doing_browser_seek_); |
(...skipping 30 matching lines...) Expand all Loading... |
341 if (HasVideo()) | 342 if (HasVideo()) |
342 video_decoder_job_->BeginPrerolling(preroll_timestamp_); | 343 video_decoder_job_->BeginPrerolling(preroll_timestamp_); |
343 prerolling_ = true; | 344 prerolling_ = true; |
344 | 345 |
345 if (!doing_browser_seek_) | 346 if (!doing_browser_seek_) |
346 manager()->OnSeekComplete(player_id(), current_time); | 347 manager()->OnSeekComplete(player_id(), current_time); |
347 | 348 |
348 ProcessPendingEvents(); | 349 ProcessPendingEvents(); |
349 } | 350 } |
350 | 351 |
351 void MediaSourcePlayer::UpdateTimestamps( | 352 void LegacyMediaSourcePlayer::UpdateTimestamps( |
352 base::TimeDelta current_presentation_timestamp, | 353 base::TimeDelta current_presentation_timestamp, |
353 base::TimeDelta max_presentation_timestamp) { | 354 base::TimeDelta max_presentation_timestamp) { |
354 interpolator_.SetBounds(current_presentation_timestamp, | 355 interpolator_.SetBounds(current_presentation_timestamp, |
355 max_presentation_timestamp); | 356 max_presentation_timestamp); |
356 manager()->OnTimeUpdate(player_id(), | 357 manager()->OnTimeUpdate(player_id(), |
357 GetCurrentTime(), | 358 GetCurrentTime(), |
358 base::TimeTicks::Now()); | 359 base::TimeTicks::Now()); |
359 } | 360 } |
360 | 361 |
361 void MediaSourcePlayer::ProcessPendingEvents() { | 362 void LegacyMediaSourcePlayer::ProcessPendingEvents() { |
362 DVLOG(1) << __FUNCTION__ << " : 0x" << std::hex << pending_event_; | 363 DVLOG(1) << __FUNCTION__ << " : 0x" << std::hex << pending_event_; |
363 // Wait for all the decoding jobs to finish before processing pending tasks. | 364 // Wait for all the decoding jobs to finish before processing pending tasks. |
364 if (video_decoder_job_->is_decoding()) { | 365 if (video_decoder_job_->is_decoding()) { |
365 DVLOG(1) << __FUNCTION__ << " : A video job is still decoding."; | 366 DVLOG(1) << __FUNCTION__ << " : A video job is still decoding."; |
366 return; | 367 return; |
367 } | 368 } |
368 | 369 |
369 if (audio_decoder_job_->is_decoding()) { | 370 if (audio_decoder_job_->is_decoding()) { |
370 DVLOG(1) << __FUNCTION__ << " : An audio job is still decoding."; | 371 DVLOG(1) << __FUNCTION__ << " : An audio job is still decoding."; |
371 return; | 372 return; |
(...skipping 26 matching lines...) Expand all Loading... |
398 | 399 |
399 // It is possible that all streams have finished decode, yet starvation | 400 // It is possible that all streams have finished decode, yet starvation |
400 // occurred during the last stream's EOS decode. In this case, prefetch is a | 401 // occurred during the last stream's EOS decode. In this case, prefetch is a |
401 // no-op. | 402 // no-op. |
402 ClearPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); | 403 ClearPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); |
403 if (count == 0) | 404 if (count == 0) |
404 return; | 405 return; |
405 | 406 |
406 SetPendingEvent(PREFETCH_DONE_EVENT_PENDING); | 407 SetPendingEvent(PREFETCH_DONE_EVENT_PENDING); |
407 base::Closure barrier = BarrierClosure( | 408 base::Closure barrier = BarrierClosure( |
408 count, base::Bind(&MediaSourcePlayer::OnPrefetchDone, weak_this_)); | 409 count, |
| 410 base::Bind(&LegacyMediaSourcePlayer::OnPrefetchDone, weak_this_)); |
409 | 411 |
410 if (!AudioFinished()) | 412 if (!AudioFinished()) |
411 audio_decoder_job_->Prefetch(barrier); | 413 audio_decoder_job_->Prefetch(barrier); |
412 | 414 |
413 if (!VideoFinished()) | 415 if (!VideoFinished()) |
414 video_decoder_job_->Prefetch(barrier); | 416 video_decoder_job_->Prefetch(barrier); |
415 | 417 |
416 return; | 418 return; |
417 } | 419 } |
418 | 420 |
419 DCHECK_EQ(pending_event_, NO_EVENT_PENDING); | 421 DCHECK_EQ(pending_event_, NO_EVENT_PENDING); |
420 | 422 |
421 // Now that all pending events have been handled, resume decoding if we are | 423 // Now that all pending events have been handled, resume decoding if we are |
422 // still playing. | 424 // still playing. |
423 if (playing_) | 425 if (playing_) |
424 StartInternal(); | 426 StartInternal(); |
425 } | 427 } |
426 | 428 |
427 void MediaSourcePlayer::MediaDecoderCallback( | 429 void LegacyMediaSourcePlayer::MediaDecoderCallback( |
428 bool is_audio, MediaCodecStatus status, | 430 bool is_audio, MediaCodecStatus status, |
429 base::TimeDelta current_presentation_timestamp, | 431 base::TimeDelta current_presentation_timestamp, |
430 base::TimeDelta max_presentation_timestamp) { | 432 base::TimeDelta max_presentation_timestamp) { |
431 DVLOG(1) << __FUNCTION__ << ": " << is_audio << ", " << status; | 433 DVLOG(1) << __FUNCTION__ << ": " << is_audio << ", " << status; |
432 | 434 |
433 // TODO(xhwang): Drop IntToString() when http://crbug.com/303899 is fixed. | 435 // TODO(xhwang): Drop IntToString() when http://crbug.com/303899 is fixed. |
434 if (is_audio) { | 436 if (is_audio) { |
435 TRACE_EVENT_ASYNC_END1("media", | 437 TRACE_EVENT_ASYNC_END1("media", |
436 "MediaSourcePlayer::DecodeMoreAudio", | 438 "LegacyMediaSourcePlayer::DecodeMoreAudio", |
437 audio_decoder_job_.get(), | 439 audio_decoder_job_.get(), |
438 "MediaCodecStatus", | 440 "MediaCodecStatus", |
439 base::IntToString(status)); | 441 base::IntToString(status)); |
440 } else { | 442 } else { |
441 TRACE_EVENT_ASYNC_END1("media", | 443 TRACE_EVENT_ASYNC_END1("media", |
442 "MediaSourcePlayer::DecodeMoreVideo", | 444 "LegacyMediaSourcePlayer::DecodeMoreVideo", |
443 video_decoder_job_.get(), | 445 video_decoder_job_.get(), |
444 "MediaCodecStatus", | 446 "MediaCodecStatus", |
445 base::IntToString(status)); | 447 base::IntToString(status)); |
446 } | 448 } |
447 | 449 |
448 // Let tests hook the completion of this decode cycle. | 450 // Let tests hook the completion of this decode cycle. |
449 if (!decode_callback_for_testing_.is_null()) | 451 if (!decode_callback_for_testing_.is_null()) |
450 base::ResetAndReturn(&decode_callback_for_testing_).Run(); | 452 base::ResetAndReturn(&decode_callback_for_testing_).Run(); |
451 | 453 |
452 bool is_clock_manager = is_audio || !HasAudio(); | 454 bool is_clock_manager = is_audio || !HasAudio(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 else | 563 else |
562 start_time_ticks_ = base::TimeTicks::Now(); | 564 start_time_ticks_ = base::TimeTicks::Now(); |
563 } | 565 } |
564 | 566 |
565 if (is_audio) | 567 if (is_audio) |
566 DecodeMoreAudio(); | 568 DecodeMoreAudio(); |
567 else | 569 else |
568 DecodeMoreVideo(); | 570 DecodeMoreVideo(); |
569 } | 571 } |
570 | 572 |
571 bool MediaSourcePlayer::IsPrerollFinished(bool is_audio) const { | 573 bool LegacyMediaSourcePlayer::IsPrerollFinished(bool is_audio) const { |
572 if (is_audio) | 574 if (is_audio) |
573 return !HasAudio() || !audio_decoder_job_->prerolling(); | 575 return !HasAudio() || !audio_decoder_job_->prerolling(); |
574 return !HasVideo() || !video_decoder_job_->prerolling(); | 576 return !HasVideo() || !video_decoder_job_->prerolling(); |
575 } | 577 } |
576 | 578 |
577 void MediaSourcePlayer::DecodeMoreAudio() { | 579 void LegacyMediaSourcePlayer::DecodeMoreAudio() { |
578 DVLOG(1) << __FUNCTION__; | 580 DVLOG(1) << __FUNCTION__; |
579 DCHECK(!audio_decoder_job_->is_decoding()); | 581 DCHECK(!audio_decoder_job_->is_decoding()); |
580 DCHECK(!AudioFinished()); | 582 DCHECK(!AudioFinished()); |
581 | 583 |
582 MediaDecoderJob::MediaDecoderJobStatus status = audio_decoder_job_->Decode( | 584 MediaDecoderJob::MediaDecoderJobStatus status = audio_decoder_job_->Decode( |
583 start_time_ticks_, | 585 start_time_ticks_, |
584 start_presentation_timestamp_, | 586 start_presentation_timestamp_, |
585 base::Bind(&MediaSourcePlayer::MediaDecoderCallback, weak_this_, true)); | 587 base::Bind(&LegacyMediaSourcePlayer::MediaDecoderCallback, |
| 588 weak_this_, true)); |
586 | 589 |
587 switch (status) { | 590 switch (status) { |
588 case MediaDecoderJob::STATUS_SUCCESS: | 591 case MediaDecoderJob::STATUS_SUCCESS: |
589 TRACE_EVENT_ASYNC_BEGIN0("media", "MediaSourcePlayer::DecodeMoreAudio", | 592 TRACE_EVENT_ASYNC_BEGIN0("media", |
| 593 "LegacyMediaSourcePlayer::DecodeMoreAudio", |
590 audio_decoder_job_.get()); | 594 audio_decoder_job_.get()); |
591 break; | 595 break; |
592 case MediaDecoderJob::STATUS_KEY_FRAME_REQUIRED: | 596 case MediaDecoderJob::STATUS_KEY_FRAME_REQUIRED: |
593 NOTREACHED(); | 597 NOTREACHED(); |
594 break; | 598 break; |
595 case MediaDecoderJob::STATUS_FAILURE: | 599 case MediaDecoderJob::STATUS_FAILURE: |
596 is_waiting_for_audio_decoder_ = true; | 600 is_waiting_for_audio_decoder_ = true; |
597 if (!IsEventPending(DECODER_CREATION_EVENT_PENDING)) | 601 if (!IsEventPending(DECODER_CREATION_EVENT_PENDING)) |
598 SetPendingEvent(DECODER_CREATION_EVENT_PENDING); | 602 SetPendingEvent(DECODER_CREATION_EVENT_PENDING); |
599 break; | 603 break; |
600 } | 604 } |
601 } | 605 } |
602 | 606 |
603 void MediaSourcePlayer::DecodeMoreVideo() { | 607 void LegacyMediaSourcePlayer::DecodeMoreVideo() { |
604 DVLOG(1) << __FUNCTION__; | 608 DVLOG(1) << __FUNCTION__; |
605 DCHECK(!video_decoder_job_->is_decoding()); | 609 DCHECK(!video_decoder_job_->is_decoding()); |
606 DCHECK(!VideoFinished()); | 610 DCHECK(!VideoFinished()); |
607 | 611 |
608 MediaDecoderJob::MediaDecoderJobStatus status = video_decoder_job_->Decode( | 612 MediaDecoderJob::MediaDecoderJobStatus status = video_decoder_job_->Decode( |
609 start_time_ticks_, | 613 start_time_ticks_, |
610 start_presentation_timestamp_, | 614 start_presentation_timestamp_, |
611 base::Bind(&MediaSourcePlayer::MediaDecoderCallback, weak_this_, | 615 base::Bind(&LegacyMediaSourcePlayer::MediaDecoderCallback, weak_this_, |
612 false)); | 616 false)); |
613 | 617 |
614 switch (status) { | 618 switch (status) { |
615 case MediaDecoderJob::STATUS_SUCCESS: | 619 case MediaDecoderJob::STATUS_SUCCESS: |
616 TRACE_EVENT_ASYNC_BEGIN0("media", "MediaSourcePlayer::DecodeMoreVideo", | 620 TRACE_EVENT_ASYNC_BEGIN0("media", |
| 621 "LegacyMediaSourcePlayer::DecodeMoreVideo", |
617 video_decoder_job_.get()); | 622 video_decoder_job_.get()); |
618 break; | 623 break; |
619 case MediaDecoderJob::STATUS_KEY_FRAME_REQUIRED: | 624 case MediaDecoderJob::STATUS_KEY_FRAME_REQUIRED: |
620 BrowserSeekToCurrentTime(); | 625 BrowserSeekToCurrentTime(); |
621 break; | 626 break; |
622 case MediaDecoderJob::STATUS_FAILURE: | 627 case MediaDecoderJob::STATUS_FAILURE: |
623 is_waiting_for_video_decoder_ = true; | 628 is_waiting_for_video_decoder_ = true; |
624 if (!IsEventPending(DECODER_CREATION_EVENT_PENDING)) | 629 if (!IsEventPending(DECODER_CREATION_EVENT_PENDING)) |
625 SetPendingEvent(DECODER_CREATION_EVENT_PENDING); | 630 SetPendingEvent(DECODER_CREATION_EVENT_PENDING); |
626 break; | 631 break; |
627 } | 632 } |
628 } | 633 } |
629 | 634 |
630 void MediaSourcePlayer::PlaybackCompleted(bool is_audio) { | 635 void LegacyMediaSourcePlayer::PlaybackCompleted(bool is_audio) { |
631 DVLOG(1) << __FUNCTION__ << "(" << is_audio << ")"; | 636 DVLOG(1) << __FUNCTION__ << "(" << is_audio << ")"; |
632 | 637 |
633 if (AudioFinished() && VideoFinished()) { | 638 if (AudioFinished() && VideoFinished()) { |
634 playing_ = false; | 639 playing_ = false; |
635 start_time_ticks_ = base::TimeTicks(); | 640 start_time_ticks_ = base::TimeTicks(); |
636 manager()->OnPlaybackComplete(player_id()); | 641 manager()->OnPlaybackComplete(player_id()); |
637 } | 642 } |
638 } | 643 } |
639 | 644 |
640 void MediaSourcePlayer::ClearDecodingData() { | 645 void LegacyMediaSourcePlayer::ClearDecodingData() { |
641 DVLOG(1) << __FUNCTION__; | 646 DVLOG(1) << __FUNCTION__; |
642 audio_decoder_job_->Flush(); | 647 audio_decoder_job_->Flush(); |
643 video_decoder_job_->Flush(); | 648 video_decoder_job_->Flush(); |
644 start_time_ticks_ = base::TimeTicks(); | 649 start_time_ticks_ = base::TimeTicks(); |
645 } | 650 } |
646 | 651 |
647 bool MediaSourcePlayer::HasVideo() const { | 652 bool LegacyMediaSourcePlayer::HasVideo() const { |
648 return video_decoder_job_->HasStream(); | 653 return video_decoder_job_->HasStream(); |
649 } | 654 } |
650 | 655 |
651 bool MediaSourcePlayer::HasAudio() const { | 656 bool LegacyMediaSourcePlayer::HasAudio() const { |
652 return audio_decoder_job_->HasStream(); | 657 return audio_decoder_job_->HasStream(); |
653 } | 658 } |
654 | 659 |
655 bool MediaSourcePlayer::AudioFinished() { | 660 bool LegacyMediaSourcePlayer::AudioFinished() { |
656 return audio_decoder_job_->OutputEOSReached() || !HasAudio(); | 661 return audio_decoder_job_->OutputEOSReached() || !HasAudio(); |
657 } | 662 } |
658 | 663 |
659 bool MediaSourcePlayer::VideoFinished() { | 664 bool LegacyMediaSourcePlayer::VideoFinished() { |
660 return video_decoder_job_->OutputEOSReached() || !HasVideo(); | 665 return video_decoder_job_->OutputEOSReached() || !HasVideo(); |
661 } | 666 } |
662 | 667 |
663 void MediaSourcePlayer::OnDecoderStarved() { | 668 void LegacyMediaSourcePlayer::OnDecoderStarved() { |
664 DVLOG(1) << __FUNCTION__; | 669 DVLOG(1) << __FUNCTION__; |
665 | 670 |
666 if (HasAudio()) { | 671 if (HasAudio()) { |
667 // If the starvation timer fired but there are no encoded frames | 672 // If the starvation timer fired but there are no encoded frames |
668 // in the queue we believe the demuxer (i.e. renderer process) froze. | 673 // in the queue we believe the demuxer (i.e. renderer process) froze. |
669 if (!audio_decoder_job_->HasData()) | 674 if (!audio_decoder_job_->HasData()) |
670 SetAudible(false); | 675 SetAudible(false); |
671 } | 676 } |
672 | 677 |
673 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); | 678 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING); |
674 ProcessPendingEvents(); | 679 ProcessPendingEvents(); |
675 } | 680 } |
676 | 681 |
677 void MediaSourcePlayer::StartStarvationCallback( | 682 void LegacyMediaSourcePlayer::StartStarvationCallback( |
678 base::TimeDelta current_presentation_timestamp, | 683 base::TimeDelta current_presentation_timestamp, |
679 base::TimeDelta max_presentation_timestamp) { | 684 base::TimeDelta max_presentation_timestamp) { |
680 // 20ms was chosen because it is the typical size of a compressed audio frame. | 685 // 20ms was chosen because it is the typical size of a compressed audio frame. |
681 // Anything smaller than this would likely cause unnecessary cycling in and | 686 // Anything smaller than this would likely cause unnecessary cycling in and |
682 // out of the prefetch state. | 687 // out of the prefetch state. |
683 const base::TimeDelta kMinStarvationTimeout = | 688 const base::TimeDelta kMinStarvationTimeout = |
684 base::TimeDelta::FromMilliseconds(20); | 689 base::TimeDelta::FromMilliseconds(20); |
685 | 690 |
686 base::TimeDelta current_timestamp = GetCurrentTime(); | 691 base::TimeDelta current_timestamp = GetCurrentTime(); |
687 base::TimeDelta timeout; | 692 base::TimeDelta timeout; |
688 if (HasAudio()) { | 693 if (HasAudio()) { |
689 timeout = max_presentation_timestamp - current_timestamp; | 694 timeout = max_presentation_timestamp - current_timestamp; |
690 } else { | 695 } else { |
691 DCHECK(current_timestamp <= current_presentation_timestamp); | 696 DCHECK(current_timestamp <= current_presentation_timestamp); |
692 | 697 |
693 // For video only streams, fps can be estimated from the difference | 698 // For video only streams, fps can be estimated from the difference |
694 // between the previous and current presentation timestamps. The | 699 // between the previous and current presentation timestamps. The |
695 // previous presentation timestamp is equal to current_timestamp. | 700 // previous presentation timestamp is equal to current_timestamp. |
696 // TODO(qinmin): determine whether 2 is a good coefficient for estimating | 701 // TODO(qinmin): determine whether 2 is a good coefficient for estimating |
697 // video frame timeout. | 702 // video frame timeout. |
698 timeout = 2 * (current_presentation_timestamp - current_timestamp); | 703 timeout = 2 * (current_presentation_timestamp - current_timestamp); |
699 } | 704 } |
700 | 705 |
701 timeout = std::max(timeout, kMinStarvationTimeout); | 706 timeout = std::max(timeout, kMinStarvationTimeout); |
702 | 707 |
703 decoder_starvation_callback_.Reset( | 708 decoder_starvation_callback_.Reset( |
704 base::Bind(&MediaSourcePlayer::OnDecoderStarved, weak_this_)); | 709 base::Bind(&LegacyMediaSourcePlayer::OnDecoderStarved, weak_this_)); |
705 base::MessageLoop::current()->PostDelayedTask( | 710 base::MessageLoop::current()->PostDelayedTask( |
706 FROM_HERE, decoder_starvation_callback_.callback(), timeout); | 711 FROM_HERE, decoder_starvation_callback_.callback(), timeout); |
707 } | 712 } |
708 | 713 |
709 void MediaSourcePlayer::OnPrefetchDone() { | 714 void LegacyMediaSourcePlayer::OnPrefetchDone() { |
710 DVLOG(1) << __FUNCTION__; | 715 DVLOG(1) << __FUNCTION__; |
711 DCHECK(!audio_decoder_job_->is_decoding()); | 716 DCHECK(!audio_decoder_job_->is_decoding()); |
712 DCHECK(!video_decoder_job_->is_decoding()); | 717 DCHECK(!video_decoder_job_->is_decoding()); |
713 | 718 |
714 // A previously posted OnPrefetchDone() could race against a Release(). If | 719 // A previously posted OnPrefetchDone() could race against a Release(). If |
715 // Release() won the race, we should no longer have decoder jobs. | 720 // Release() won the race, we should no longer have decoder jobs. |
716 // TODO(qinmin/wolenetz): Maintain channel state to not double-request data | 721 // TODO(qinmin/wolenetz): Maintain channel state to not double-request data |
717 // or drop data received across Release()+Start(). See http://crbug.com/306314 | 722 // or drop data received across Release()+Start(). See http://crbug.com/306314 |
718 // and http://crbug.com/304234. | 723 // and http://crbug.com/304234. |
719 if (!IsEventPending(PREFETCH_DONE_EVENT_PENDING)) { | 724 if (!IsEventPending(PREFETCH_DONE_EVENT_PENDING)) { |
(...skipping 16 matching lines...) Expand all Loading... |
736 if (!interpolator_.interpolating()) | 741 if (!interpolator_.interpolating()) |
737 interpolator_.StartInterpolating(); | 742 interpolator_.StartInterpolating(); |
738 | 743 |
739 if (!AudioFinished()) | 744 if (!AudioFinished()) |
740 DecodeMoreAudio(); | 745 DecodeMoreAudio(); |
741 | 746 |
742 if (!VideoFinished()) | 747 if (!VideoFinished()) |
743 DecodeMoreVideo(); | 748 DecodeMoreVideo(); |
744 } | 749 } |
745 | 750 |
746 void MediaSourcePlayer::OnDemuxerConfigsChanged() { | 751 void LegacyMediaSourcePlayer::OnDemuxerConfigsChanged() { |
747 manager()->OnMediaMetadataChanged( | 752 manager()->OnMediaMetadataChanged( |
748 player_id(), duration_, GetVideoWidth(), GetVideoHeight(), true); | 753 player_id(), duration_, GetVideoWidth(), GetVideoHeight(), true); |
749 } | 754 } |
750 | 755 |
751 const char* MediaSourcePlayer::GetEventName(PendingEventFlags event) { | 756 const char* LegacyMediaSourcePlayer::GetEventName(PendingEventFlags event) { |
752 // Please keep this in sync with PendingEventFlags. | 757 // Please keep this in sync with PendingEventFlags. |
753 static const char* kPendingEventNames[] = { | 758 static const char* kPendingEventNames[] = { |
754 "PREFETCH_DONE", | 759 "PREFETCH_DONE", |
755 "SEEK", | 760 "SEEK", |
756 "DECODER_CREATION", | 761 "DECODER_CREATION", |
757 "PREFETCH_REQUEST", | 762 "PREFETCH_REQUEST", |
758 }; | 763 }; |
759 | 764 |
760 int mask = 1; | 765 int mask = 1; |
761 for (size_t i = 0; i < arraysize(kPendingEventNames); ++i, mask <<= 1) { | 766 for (size_t i = 0; i < arraysize(kPendingEventNames); ++i, mask <<= 1) { |
762 if (event & mask) | 767 if (event & mask) |
763 return kPendingEventNames[i]; | 768 return kPendingEventNames[i]; |
764 } | 769 } |
765 | 770 |
766 return "UNKNOWN"; | 771 return "UNKNOWN"; |
767 } | 772 } |
768 | 773 |
769 bool MediaSourcePlayer::IsEventPending(PendingEventFlags event) const { | 774 bool LegacyMediaSourcePlayer::IsEventPending(PendingEventFlags event) const { |
770 return pending_event_ & event; | 775 return pending_event_ & event; |
771 } | 776 } |
772 | 777 |
773 void MediaSourcePlayer::SetPendingEvent(PendingEventFlags event) { | 778 void LegacyMediaSourcePlayer::SetPendingEvent(PendingEventFlags event) { |
774 DVLOG(1) << __FUNCTION__ << "(" << GetEventName(event) << ")"; | 779 DVLOG(1) << __FUNCTION__ << "(" << GetEventName(event) << ")"; |
775 DCHECK_NE(event, NO_EVENT_PENDING); | 780 DCHECK_NE(event, NO_EVENT_PENDING); |
776 DCHECK(!IsEventPending(event)); | 781 DCHECK(!IsEventPending(event)); |
777 | 782 |
778 pending_event_ |= event; | 783 pending_event_ |= event; |
779 } | 784 } |
780 | 785 |
781 void MediaSourcePlayer::ClearPendingEvent(PendingEventFlags event) { | 786 void LegacyMediaSourcePlayer::ClearPendingEvent(PendingEventFlags event) { |
782 DVLOG(1) << __FUNCTION__ << "(" << GetEventName(event) << ")"; | 787 DVLOG(1) << __FUNCTION__ << "(" << GetEventName(event) << ")"; |
783 DCHECK_NE(event, NO_EVENT_PENDING); | 788 DCHECK_NE(event, NO_EVENT_PENDING); |
784 DCHECK(IsEventPending(event)) << GetEventName(event); | 789 DCHECK(IsEventPending(event)) << GetEventName(event); |
785 | 790 |
786 pending_event_ &= ~event; | 791 pending_event_ &= ~event; |
787 } | 792 } |
788 | 793 |
789 void MediaSourcePlayer::RetryDecoderCreation(bool audio, bool video) { | 794 void LegacyMediaSourcePlayer::RetryDecoderCreation(bool audio, bool video) { |
790 if (audio) | 795 if (audio) |
791 is_waiting_for_audio_decoder_ = false; | 796 is_waiting_for_audio_decoder_ = false; |
792 if (video) | 797 if (video) |
793 is_waiting_for_video_decoder_ = false; | 798 is_waiting_for_video_decoder_ = false; |
794 if (IsEventPending(DECODER_CREATION_EVENT_PENDING)) | 799 if (IsEventPending(DECODER_CREATION_EVENT_PENDING)) |
795 ProcessPendingEvents(); | 800 ProcessPendingEvents(); |
796 } | 801 } |
797 | 802 |
798 void MediaSourcePlayer::OnKeyAdded() { | 803 void LegacyMediaSourcePlayer::OnKeyAdded() { |
799 DVLOG(1) << __FUNCTION__; | 804 DVLOG(1) << __FUNCTION__; |
800 | 805 |
801 if (is_waiting_for_key_) { | 806 if (is_waiting_for_key_) { |
802 ResumePlaybackAfterKeyAdded(); | 807 ResumePlaybackAfterKeyAdded(); |
803 return; | 808 return; |
804 } | 809 } |
805 | 810 |
806 if ((audio_decoder_job_->is_content_encrypted() && | 811 if ((audio_decoder_job_->is_content_encrypted() && |
807 audio_decoder_job_->is_decoding()) || | 812 audio_decoder_job_->is_decoding()) || |
808 (video_decoder_job_->is_content_encrypted() && | 813 (video_decoder_job_->is_content_encrypted() && |
809 video_decoder_job_->is_decoding())) { | 814 video_decoder_job_->is_decoding())) { |
810 DVLOG(1) << __FUNCTION__ << ": " << "Key added during pending decode."; | 815 DVLOG(1) << __FUNCTION__ << ": " << "Key added during pending decode."; |
811 key_added_while_decode_pending_ = true; | 816 key_added_while_decode_pending_ = true; |
812 } | 817 } |
813 } | 818 } |
814 | 819 |
815 void MediaSourcePlayer::ResumePlaybackAfterKeyAdded() { | 820 void LegacyMediaSourcePlayer::ResumePlaybackAfterKeyAdded() { |
816 DVLOG(1) << __FUNCTION__; | 821 DVLOG(1) << __FUNCTION__; |
817 DCHECK(is_waiting_for_key_ || key_added_while_decode_pending_); | 822 DCHECK(is_waiting_for_key_ || key_added_while_decode_pending_); |
818 | 823 |
819 is_waiting_for_key_ = false; | 824 is_waiting_for_key_ = false; |
820 key_added_while_decode_pending_ = false; | 825 key_added_while_decode_pending_ = false; |
821 | 826 |
822 // StartInternal() will trigger a prefetch, where in most cases we'll just | 827 // StartInternal() will trigger a prefetch, where in most cases we'll just |
823 // use previously received data. | 828 // use previously received data. |
824 if (playing_) | 829 if (playing_) |
825 StartInternal(); | 830 StartInternal(); |
826 } | 831 } |
827 | 832 |
828 void MediaSourcePlayer::OnCdmUnset() { | 833 void LegacyMediaSourcePlayer::OnCdmUnset() { |
829 DVLOG(1) << __FUNCTION__; | 834 DVLOG(1) << __FUNCTION__; |
830 DCHECK(drm_bridge_); | 835 DCHECK(drm_bridge_); |
831 // TODO(xhwang): Currently this is only called during teardown. Support full | 836 // TODO(xhwang): Currently this is only called during teardown. Support full |
832 // detachment of CDM during playback. This will be needed when we start to | 837 // detachment of CDM during playback. This will be needed when we start to |
833 // support setMediaKeys(0) (see http://crbug.com/330324), or when we release | 838 // support setMediaKeys(0) (see http://crbug.com/330324), or when we release |
834 // MediaDrm when the video is paused, or when the device goes to sleep (see | 839 // MediaDrm when the video is paused, or when the device goes to sleep (see |
835 // http://crbug.com/272421). | 840 // http://crbug.com/272421). |
836 audio_decoder_job_->SetDrmBridge(NULL); | 841 audio_decoder_job_->SetDrmBridge(NULL); |
837 video_decoder_job_->SetDrmBridge(NULL); | 842 video_decoder_job_->SetDrmBridge(NULL); |
838 cdm_registration_id_ = 0; | 843 cdm_registration_id_ = 0; |
839 drm_bridge_ = NULL; | 844 drm_bridge_ = NULL; |
840 } | 845 } |
841 | 846 |
842 } // namespace media | 847 } // namespace media |
OLD | NEW |