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
3 // found in the LICENSE file.
5 #include "media/base/android/media_source_player.h"
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/barrier_closure.h"
12 #include "base/basictypes.h"
13 #include "base/bind.h"
14 #include "base/callback_helpers.h"
15 #include "base/debug/trace_event.h"
16 #include "base/logging.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "media/base/android/audio_decoder_job.h"
19 #include "media/base/android/media_drm_bridge.h"
20 #include "media/base/android/media_player_manager.h"
21 #include "media/base/android/video_decoder_job.h"
26 MediaSourcePlayer::MediaSourcePlayer(
28 MediaPlayerManager* manager,
29 const RequestMediaResourcesCB& request_media_resources_cb,
30 scoped_ptr<DemuxerAndroid> demuxer,
31 const GURL& frame_url)
32 : MediaPlayerAndroid(player_id,
34 request_media_resources_cb,
36 demuxer_(demuxer.Pass()),
37 pending_event_(NO_EVENT_PENDING),
39 interpolator_(&default_tick_clock_),
40 doing_browser_seek_(false),
43 cdm_registration_id_(0),
44 is_waiting_for_key_(false),
45 is_waiting_for_audio_decoder_(false),
46 is_waiting_for_video_decoder_(false),
49 audio_decoder_job_.reset(new AudioDecoderJob(
50 base::Bind(&DemuxerAndroid::RequestDemuxerData,
51 base::Unretained(demuxer_.get()),
52 DemuxerStream::AUDIO),
53 base::Bind(&MediaSourcePlayer::OnDemuxerConfigsChanged,
54 weak_factory_.GetWeakPtr())));
55 video_decoder_job_.reset(new VideoDecoderJob(
56 base::Bind(&DemuxerAndroid::RequestDemuxerData,
57 base::Unretained(demuxer_.get()),
58 DemuxerStream::VIDEO),
59 base::Bind(request_media_resources_cb_, player_id),
60 base::Bind(&MediaSourcePlayer::OnDemuxerConfigsChanged,
61 weak_factory_.GetWeakPtr())));
62 demuxer_->Initialize(this);
63 interpolator_.SetUpperBound(base::TimeDelta());
64 weak_this_ = weak_factory_.GetWeakPtr();
67 MediaSourcePlayer::~MediaSourcePlayer() {
69 DCHECK_EQ(!drm_bridge_, !cdm_registration_id_);
71 drm_bridge_->UnregisterPlayer(cdm_registration_id_);
72 cdm_registration_id_ = 0;
76 void MediaSourcePlayer::SetVideoSurface(gfx::ScopedJavaSurface surface) {
77 DVLOG(1) << __FUNCTION__;
78 if (!video_decoder_job_->SetVideoSurface(surface.Pass()))
80 // Retry video decoder creation.
81 RetryDecoderCreation(false, true);
84 void MediaSourcePlayer::ScheduleSeekEventAndStopDecoding(
85 base::TimeDelta seek_time) {
86 DVLOG(1) << __FUNCTION__ << "(" << seek_time.InSecondsF() << ")";
87 DCHECK(!IsEventPending(SEEK_EVENT_PENDING));
89 pending_seek_ = false;
91 interpolator_.SetBounds(seek_time, seek_time);
93 if (audio_decoder_job_->is_decoding())
94 audio_decoder_job_->StopDecode();
95 if (video_decoder_job_->is_decoding())
96 video_decoder_job_->StopDecode();
98 SetPendingEvent(SEEK_EVENT_PENDING);
99 ProcessPendingEvents();
102 void MediaSourcePlayer::BrowserSeekToCurrentTime() {
103 DVLOG(1) << __FUNCTION__;
105 DCHECK(!IsEventPending(SEEK_EVENT_PENDING));
106 doing_browser_seek_ = true;
107 ScheduleSeekEventAndStopDecoding(GetCurrentTime());
110 bool MediaSourcePlayer::Seekable() {
111 // If the duration TimeDelta, converted to milliseconds from microseconds,
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
114 // values at millisecond resolution.
116 base::TimeDelta::FromMilliseconds(std::numeric_limits<int32>::max());
119 void MediaSourcePlayer::Start() {
120 DVLOG(1) << __FUNCTION__;
124 bool request_fullscreen = IsProtectedSurfaceRequired();
125 #if defined(VIDEO_HOLE)
126 // Skip to request fullscreen when hole-punching is used.
127 request_fullscreen = request_fullscreen &&
128 !manager()->ShouldUseVideoOverlayForEmbeddedEncryptedVideo();
129 #endif // defined(VIDEO_HOLE)
130 if (request_fullscreen)
131 manager()->RequestFullScreen(player_id());
136 void MediaSourcePlayer::Pause(bool is_media_related_action) {
137 DVLOG(1) << __FUNCTION__;
139 // Since decoder jobs have their own thread, decoding is not fully paused
140 // until all the decoder jobs call MediaDecoderCallback(). It is possible
141 // that Start() is called while the player is waiting for
142 // MediaDecoderCallback(). In that case, decoding will continue when
143 // MediaDecoderCallback() is called.
145 start_time_ticks_ = base::TimeTicks();
148 bool MediaSourcePlayer::IsPlaying() {
152 int MediaSourcePlayer::GetVideoWidth() {
153 return video_decoder_job_->output_width();
156 int MediaSourcePlayer::GetVideoHeight() {
157 return video_decoder_job_->output_height();
160 void MediaSourcePlayer::SeekTo(base::TimeDelta timestamp) {
161 DVLOG(1) << __FUNCTION__ << "(" << timestamp.InSecondsF() << ")";
163 if (IsEventPending(SEEK_EVENT_PENDING)) {
164 DCHECK(doing_browser_seek_) << "SeekTo while SeekTo in progress";
165 DCHECK(!pending_seek_) << "SeekTo while SeekTo pending browser seek";
167 // There is a browser seek currently in progress to obtain I-frame to feed
168 // a newly constructed video decoder. Remember this real seek request so
169 // it can be initiated once OnDemuxerSeekDone() occurs for the browser seek.
170 pending_seek_ = true;
171 pending_seek_time_ = timestamp;
175 doing_browser_seek_ = false;
176 ScheduleSeekEventAndStopDecoding(timestamp);
179 base::TimeDelta MediaSourcePlayer::GetCurrentTime() {
180 return std::min(interpolator_.GetInterpolatedTime(), duration_);
183 base::TimeDelta MediaSourcePlayer::GetDuration() {
187 void MediaSourcePlayer::Release() {
188 DVLOG(1) << __FUNCTION__;
190 audio_decoder_job_->ReleaseDecoderResources();
191 video_decoder_job_->ReleaseDecoderResources();
193 // Prevent player restart, including job re-creation attempts.
196 decoder_starvation_callback_.Cancel();
200 void MediaSourcePlayer::SetVolume(double volume) {
201 audio_decoder_job_->SetVolume(volume);
204 bool MediaSourcePlayer::CanPause() {
208 bool MediaSourcePlayer::CanSeekForward() {
212 bool MediaSourcePlayer::CanSeekBackward() {
216 bool MediaSourcePlayer::IsPlayerReady() {
217 return audio_decoder_job_ || video_decoder_job_;
220 void MediaSourcePlayer::StartInternal() {
221 DVLOG(1) << __FUNCTION__;
222 // If there are pending events, wait for them finish.
223 if (pending_event_ != NO_EVENT_PENDING)
226 // When we start, we'll have new demuxed data coming in. This new data could
227 // be clear (not encrypted) or encrypted with different keys. So
228 // |is_waiting_for_key_| condition may not be true anymore.
229 is_waiting_for_key_ = false;
230 AttachListener(NULL);
232 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING);
233 ProcessPendingEvents();
236 void MediaSourcePlayer::OnDemuxerConfigsAvailable(
237 const DemuxerConfigs& configs) {
238 DVLOG(1) << __FUNCTION__;
239 DCHECK(!HasAudio() && !HasVideo());
240 duration_ = configs.duration;
242 audio_decoder_job_->SetDemuxerConfigs(configs);
243 video_decoder_job_->SetDemuxerConfigs(configs);
244 OnDemuxerConfigsChanged();
247 void MediaSourcePlayer::OnDemuxerDataAvailable(const DemuxerData& data) {
248 DVLOG(1) << __FUNCTION__ << "(" << data.type << ")";
249 DCHECK_LT(0u, data.access_units.size());
250 CHECK_GE(1u, data.demuxer_configs.size());
252 if (data.type == DemuxerStream::AUDIO)
253 audio_decoder_job_->OnDataReceived(data);
254 else if (data.type == DemuxerStream::VIDEO)
255 video_decoder_job_->OnDataReceived(data);
258 void MediaSourcePlayer::OnDemuxerDurationChanged(base::TimeDelta duration) {
259 duration_ = duration;
262 void MediaSourcePlayer::OnMediaCryptoReady() {
263 DCHECK(!drm_bridge_->GetMediaCrypto().is_null());
264 drm_bridge_->SetMediaCryptoReadyCB(base::Closure());
266 // Retry decoder creation if the decoders are waiting for MediaCrypto.
267 RetryDecoderCreation(true, true);
270 void MediaSourcePlayer::SetCdm(BrowserCdm* cdm) {
271 // Currently we don't support DRM change during the middle of playback, even
272 // if the player is paused.
273 // TODO(qinmin): support DRM change after playback has started.
274 // http://crbug.com/253792.
275 if (GetCurrentTime() > base::TimeDelta()) {
276 VLOG(0) << "Setting DRM bridge after playback has started. "
277 << "This is not well supported!";
281 NOTREACHED() << "Currently we do not support resetting CDM.";
285 // Only MediaDrmBridge will be set on MediaSourcePlayer.
286 drm_bridge_ = static_cast<MediaDrmBridge*>(cdm);
288 cdm_registration_id_ = drm_bridge_->RegisterPlayer(
289 base::Bind(&MediaSourcePlayer::OnKeyAdded, weak_this_),
290 base::Bind(&MediaSourcePlayer::OnCdmUnset, weak_this_));
292 audio_decoder_job_->SetDrmBridge(drm_bridge_);
293 video_decoder_job_->SetDrmBridge(drm_bridge_);
295 if (drm_bridge_->GetMediaCrypto().is_null()) {
296 drm_bridge_->SetMediaCryptoReadyCB(
297 base::Bind(&MediaSourcePlayer::OnMediaCryptoReady, weak_this_));
301 // If the player is previously waiting for CDM, retry decoder creation.
302 RetryDecoderCreation(true, true);
305 void MediaSourcePlayer::OnDemuxerSeekDone(
306 base::TimeDelta actual_browser_seek_time) {
307 DVLOG(1) << __FUNCTION__;
309 ClearPendingEvent(SEEK_EVENT_PENDING);
310 if (IsEventPending(PREFETCH_REQUEST_EVENT_PENDING))
311 ClearPendingEvent(PREFETCH_REQUEST_EVENT_PENDING);
314 DVLOG(1) << __FUNCTION__ << "processing pending seek";
315 DCHECK(doing_browser_seek_);
316 pending_seek_ = false;
317 SeekTo(pending_seek_time_);
321 // It is possible that a browser seek to I-frame had to seek to a buffered
322 // I-frame later than the requested one due to data removal or GC. Update
323 // player clock to the actual seek target.
324 if (doing_browser_seek_) {
325 DCHECK(actual_browser_seek_time != kNoTimestamp());
326 base::TimeDelta seek_time = actual_browser_seek_time;
327 // A browser seek must not jump into the past. Ideally, it seeks to the
328 // requested time, but it might jump into the future.
329 DCHECK(seek_time >= GetCurrentTime());
330 DVLOG(1) << __FUNCTION__ << " : setting clock to actual browser seek time: "
331 << seek_time.InSecondsF();
332 interpolator_.SetBounds(seek_time, seek_time);
333 audio_decoder_job_->SetBaseTimestamp(seek_time);
335 DCHECK(actual_browser_seek_time == kNoTimestamp());
338 base::TimeDelta current_time = GetCurrentTime();
339 // TODO(qinmin): Simplify the logic by using |start_presentation_timestamp_|
340 // to preroll media decoder jobs. Currently |start_presentation_timestamp_|
341 // is calculated from decoder output, while preroll relies on the access
342 // unit's timestamp. There are some differences between the two.
343 preroll_timestamp_ = current_time;
345 audio_decoder_job_->BeginPrerolling(preroll_timestamp_);
347 video_decoder_job_->BeginPrerolling(preroll_timestamp_);
350 if (!doing_browser_seek_)
351 manager()->OnSeekComplete(player_id(), current_time);
353 ProcessPendingEvents();
356 void MediaSourcePlayer::UpdateTimestamps(
357 base::TimeDelta current_presentation_timestamp,
358 base::TimeDelta max_presentation_timestamp) {
359 interpolator_.SetBounds(current_presentation_timestamp,
360 max_presentation_timestamp);
361 manager()->OnTimeUpdate(player_id(),
363 base::TimeTicks::Now());
366 void MediaSourcePlayer::ProcessPendingEvents() {
367 DVLOG(1) << __FUNCTION__ << " : 0x" << std::hex << pending_event_;
368 // Wait for all the decoding jobs to finish before processing pending tasks.
369 if (video_decoder_job_->is_decoding()) {
370 DVLOG(1) << __FUNCTION__ << " : A video job is still decoding.";
374 if (audio_decoder_job_->is_decoding()) {
375 DVLOG(1) << __FUNCTION__ << " : An audio job is still decoding.";
379 if (IsEventPending(PREFETCH_DONE_EVENT_PENDING)) {
380 DVLOG(1) << __FUNCTION__ << " : PREFETCH_DONE still pending.";
384 if (IsEventPending(SEEK_EVENT_PENDING)) {
385 DVLOG(1) << __FUNCTION__ << " : Handling SEEK_EVENT";
387 audio_decoder_job_->SetBaseTimestamp(GetCurrentTime());
388 demuxer_->RequestDemuxerSeek(GetCurrentTime(), doing_browser_seek_);
392 if (IsEventPending(DECODER_CREATION_EVENT_PENDING)) {
393 // Don't continue if one of the decoder is not created.
394 if (is_waiting_for_audio_decoder_ || is_waiting_for_video_decoder_)
396 ClearPendingEvent(DECODER_CREATION_EVENT_PENDING);
399 if (IsEventPending(PREFETCH_REQUEST_EVENT_PENDING)) {
400 DVLOG(1) << __FUNCTION__ << " : Handling PREFETCH_REQUEST_EVENT.";
401 int count = (AudioFinished() ? 0 : 1) + (VideoFinished() ? 0 : 1);
403 // It is possible that all streams have finished decode, yet starvation
404 // occurred during the last stream's EOS decode. In this case, prefetch is a
406 ClearPendingEvent(PREFETCH_REQUEST_EVENT_PENDING);
410 SetPendingEvent(PREFETCH_DONE_EVENT_PENDING);
411 base::Closure barrier = BarrierClosure(
412 count, base::Bind(&MediaSourcePlayer::OnPrefetchDone, weak_this_));
414 if (!AudioFinished())
415 audio_decoder_job_->Prefetch(barrier);
417 if (!VideoFinished())
418 video_decoder_job_->Prefetch(barrier);
423 DCHECK_EQ(pending_event_, NO_EVENT_PENDING);
425 // Now that all pending events have been handled, resume decoding if we are
431 void MediaSourcePlayer::MediaDecoderCallback(
432 bool is_audio, MediaCodecStatus status,
433 base::TimeDelta current_presentation_timestamp,
434 base::TimeDelta max_presentation_timestamp) {
435 DVLOG(1) << __FUNCTION__ << ": " << is_audio << ", " << status;
437 // TODO(xhwang): Drop IntToString() when http://crbug.com/303899 is fixed.
439 TRACE_EVENT_ASYNC_END1("media",
440 "MediaSourcePlayer::DecodeMoreAudio",
441 audio_decoder_job_.get(),
443 base::IntToString(status));
445 TRACE_EVENT_ASYNC_END1("media",
446 "MediaSourcePlayer::DecodeMoreVideo",
447 video_decoder_job_.get(),
449 base::IntToString(status));
452 // Let tests hook the completion of this decode cycle.
453 if (!decode_callback_for_testing_.is_null())
454 base::ResetAndReturn(&decode_callback_for_testing_).Run();
456 bool is_clock_manager = is_audio || !HasAudio();
458 if (is_clock_manager)
459 decoder_starvation_callback_.Cancel();
461 if (status == MEDIA_CODEC_ERROR) {
462 DVLOG(1) << __FUNCTION__ << " : decode error";
464 manager()->OnError(player_id(), MEDIA_ERROR_DECODE);
468 DCHECK(!IsEventPending(PREFETCH_DONE_EVENT_PENDING));
470 // Let |SEEK_EVENT_PENDING| (the highest priority event outside of
471 // |PREFETCH_DONE_EVENT_PENDING|) preempt output EOS detection here. Process
472 // any other pending events only after handling EOS detection.
473 if (IsEventPending(SEEK_EVENT_PENDING)) {
474 ProcessPendingEvents();
478 if ((status == MEDIA_CODEC_OK || status == MEDIA_CODEC_INPUT_END_OF_STREAM) &&
479 is_clock_manager && current_presentation_timestamp != kNoTimestamp()) {
480 UpdateTimestamps(current_presentation_timestamp,
481 max_presentation_timestamp);
484 if (status == MEDIA_CODEC_OUTPUT_END_OF_STREAM) {
485 PlaybackCompleted(is_audio);
486 if (is_clock_manager)
487 interpolator_.StopInterpolating();
490 if (pending_event_ != NO_EVENT_PENDING) {
491 ProcessPendingEvents();
495 if (status == MEDIA_CODEC_OUTPUT_END_OF_STREAM)
499 if (is_clock_manager)
500 interpolator_.StopInterpolating();
504 if (status == MEDIA_CODEC_NO_KEY) {
505 is_waiting_for_key_ = true;
509 // If the status is MEDIA_CODEC_STOPPED, stop decoding new data. The player is
510 // in the middle of a seek or stop event and needs to wait for the IPCs to
512 if (status == MEDIA_CODEC_STOPPED)
515 if (prerolling_ && IsPrerollFinished(is_audio)) {
516 if (IsPrerollFinished(!is_audio)) {
523 if (is_clock_manager) {
524 // If we have a valid timestamp, start the starvation callback. Otherwise,
525 // reset the |start_time_ticks_| so that the next frame will not suffer
526 // from the decoding delay caused by the current frame.
527 if (current_presentation_timestamp != kNoTimestamp())
528 StartStarvationCallback(current_presentation_timestamp,
529 max_presentation_timestamp);
531 start_time_ticks_ = base::TimeTicks::Now();
540 bool MediaSourcePlayer::IsPrerollFinished(bool is_audio) const {
542 return !HasAudio() || !audio_decoder_job_->prerolling();
543 return !HasVideo() || !video_decoder_job_->prerolling();
546 void MediaSourcePlayer::DecodeMoreAudio() {
547 DVLOG(1) << __FUNCTION__;
548 DCHECK(!audio_decoder_job_->is_decoding());
549 DCHECK(!AudioFinished());
551 if (audio_decoder_job_->Decode(
553 start_presentation_timestamp_,
554 base::Bind(&MediaSourcePlayer::MediaDecoderCallback, weak_this_, true))) {
555 TRACE_EVENT_ASYNC_BEGIN0("media", "MediaSourcePlayer::DecodeMoreAudio",
556 audio_decoder_job_.get());
560 is_waiting_for_audio_decoder_ = true;
561 if (!IsEventPending(DECODER_CREATION_EVENT_PENDING))
562 SetPendingEvent(DECODER_CREATION_EVENT_PENDING);
565 void MediaSourcePlayer::DecodeMoreVideo() {
566 DVLOG(1) << __FUNCTION__;
567 DCHECK(!video_decoder_job_->is_decoding());
568 DCHECK(!VideoFinished());
570 if (video_decoder_job_->Decode(
572 start_presentation_timestamp_,
573 base::Bind(&MediaSourcePlayer::MediaDecoderCallback, weak_this_,
575 TRACE_EVENT_ASYNC_BEGIN0("media", "MediaSourcePlayer::DecodeMoreVideo",
576 video_decoder_job_.get());
580 // If the decoder is waiting for iframe, trigger a browser seek.
581 if (!video_decoder_job_->next_video_data_is_iframe()) {
582 BrowserSeekToCurrentTime();
586 is_waiting_for_video_decoder_ = true;
587 if (!IsEventPending(DECODER_CREATION_EVENT_PENDING))
588 SetPendingEvent(DECODER_CREATION_EVENT_PENDING);
591 void MediaSourcePlayer::PlaybackCompleted(bool is_audio) {
592 DVLOG(1) << __FUNCTION__ << "(" << is_audio << ")";
594 if (AudioFinished() && VideoFinished()) {
596 start_time_ticks_ = base::TimeTicks();
597 manager()->OnPlaybackComplete(player_id());
601 void MediaSourcePlayer::ClearDecodingData() {
602 DVLOG(1) << __FUNCTION__;
603 audio_decoder_job_->Flush();
604 video_decoder_job_->Flush();
605 start_time_ticks_ = base::TimeTicks();
608 bool MediaSourcePlayer::HasVideo() const {
609 return video_decoder_job_->HasStream();
612 bool MediaSourcePlayer::HasAudio() const {
613 return audio_decoder_job_->HasStream();
616 bool MediaSourcePlayer::AudioFinished() {
617 return audio_decoder_job_->OutputEOSReached() || !HasAudio();
620 bool MediaSourcePlayer::VideoFinished() {
621 return video_decoder_job_->OutputEOSReached() || !HasVideo();
624 void MediaSourcePlayer::OnDecoderStarved() {
625 DVLOG(1) << __FUNCTION__;
626 SetPendingEvent(PREFETCH_REQUEST_EVENT_PENDING);
627 ProcessPendingEvents();
630 void MediaSourcePlayer::StartStarvationCallback(
631 base::TimeDelta current_presentation_timestamp,
632 base::TimeDelta max_presentation_timestamp) {
633 // 20ms was chosen because it is the typical size of a compressed audio frame.
634 // Anything smaller than this would likely cause unnecessary cycling in and
635 // out of the prefetch state.
636 const base::TimeDelta kMinStarvationTimeout =
637 base::TimeDelta::FromMilliseconds(20);
639 base::TimeDelta current_timestamp = GetCurrentTime();
640 base::TimeDelta timeout;
642 timeout = max_presentation_timestamp - current_timestamp;
644 DCHECK(current_timestamp <= current_presentation_timestamp);
646 // For video only streams, fps can be estimated from the difference
647 // between the previous and current presentation timestamps. The
648 // previous presentation timestamp is equal to current_timestamp.
649 // TODO(qinmin): determine whether 2 is a good coefficient for estimating
650 // video frame timeout.
651 timeout = 2 * (current_presentation_timestamp - current_timestamp);
654 timeout = std::max(timeout, kMinStarvationTimeout);
656 decoder_starvation_callback_.Reset(
657 base::Bind(&MediaSourcePlayer::OnDecoderStarved, weak_this_));
658 base::MessageLoop::current()->PostDelayedTask(
659 FROM_HERE, decoder_starvation_callback_.callback(), timeout);
662 bool MediaSourcePlayer::IsProtectedSurfaceRequired() {
663 return video_decoder_job_->is_content_encrypted() &&
664 drm_bridge_ && drm_bridge_->IsProtectedSurfaceRequired();
667 void MediaSourcePlayer::OnPrefetchDone() {
668 DVLOG(1) << __FUNCTION__;
669 DCHECK(!audio_decoder_job_->is_decoding());
670 DCHECK(!video_decoder_job_->is_decoding());
672 // A previously posted OnPrefetchDone() could race against a Release(). If
673 // Release() won the race, we should no longer have decoder jobs.
674 // TODO(qinmin/wolenetz): Maintain channel state to not double-request data
675 // or drop data received across Release()+Start(). See http://crbug.com/306314
676 // and http://crbug.com/304234.
677 if (!IsEventPending(PREFETCH_DONE_EVENT_PENDING)) {
678 DVLOG(1) << __FUNCTION__ << " : aborting";
682 ClearPendingEvent(PREFETCH_DONE_EVENT_PENDING);
684 if (pending_event_ != NO_EVENT_PENDING) {
685 ProcessPendingEvents();
692 start_time_ticks_ = base::TimeTicks::Now();
693 start_presentation_timestamp_ = GetCurrentTime();
694 if (!interpolator_.interpolating())
695 interpolator_.StartInterpolating();
697 if (!AudioFinished())
700 if (!VideoFinished())
704 void MediaSourcePlayer::OnDemuxerConfigsChanged() {
705 manager()->OnMediaMetadataChanged(
706 player_id(), duration_, GetVideoWidth(), GetVideoHeight(), true);
709 const char* MediaSourcePlayer::GetEventName(PendingEventFlags event) {
710 // Please keep this in sync with PendingEventFlags.
711 static const char* kPendingEventNames[] = {
719 for (size_t i = 0; i < arraysize(kPendingEventNames); ++i, mask <<= 1) {
721 return kPendingEventNames[i];
727 bool MediaSourcePlayer::IsEventPending(PendingEventFlags event) const {
728 return pending_event_ & event;
731 void MediaSourcePlayer::SetPendingEvent(PendingEventFlags event) {
732 DVLOG(1) << __FUNCTION__ << "(" << GetEventName(event) << ")";
733 DCHECK_NE(event, NO_EVENT_PENDING);
734 DCHECK(!IsEventPending(event));
736 pending_event_ |= event;
739 void MediaSourcePlayer::ClearPendingEvent(PendingEventFlags event) {
740 DVLOG(1) << __FUNCTION__ << "(" << GetEventName(event) << ")";
741 DCHECK_NE(event, NO_EVENT_PENDING);
742 DCHECK(IsEventPending(event)) << GetEventName(event);
744 pending_event_ &= ~event;
747 void MediaSourcePlayer::RetryDecoderCreation(bool audio, bool video) {
749 is_waiting_for_audio_decoder_ = false;
751 is_waiting_for_video_decoder_ = false;
752 if (IsEventPending(DECODER_CREATION_EVENT_PENDING))
753 ProcessPendingEvents();
756 void MediaSourcePlayer::OnKeyAdded() {
757 DVLOG(1) << __FUNCTION__;
758 if (!is_waiting_for_key_)
761 is_waiting_for_key_ = false;
766 void MediaSourcePlayer::OnCdmUnset() {
767 DVLOG(1) << __FUNCTION__;
769 // TODO(xhwang): Currently this is only called during teardown. Support full
770 // detachment of CDM during playback. This will be needed when we start to
771 // support setMediaKeys(0) (see http://crbug.com/330324), or when we release
772 // MediaDrm when the video is paused, or when the device goes to sleep (see
773 // http://crbug.com/272421).
774 audio_decoder_job_->SetDrmBridge(NULL);
775 video_decoder_job_->SetDrmBridge(NULL);
776 cdm_registration_id_ = 0;