Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1163)

Side by Side Diff: media/base/android/media_source_player.cc

Issue 16823003: Replace erroneous use of base::Time with base::TimeTicks throughout media code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/PresubmitPromptWarning/PresubmitPromptOrNotify/ Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/android/media_source_player.h ('k') | media/base/audio_renderer_mixer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/media_source_player.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 VideoDecoderJob( 78 VideoDecoderJob(
79 const VideoCodec video_codec, const gfx::Size& size, jobject surface); 79 const VideoCodec video_codec, const gfx::Size& size, jobject surface);
80 virtual ~VideoDecoderJob() {} 80 virtual ~VideoDecoderJob() {}
81 81
82 void Configure( 82 void Configure(
83 const VideoCodec codec, const gfx::Size& size, jobject surface); 83 const VideoCodec codec, const gfx::Size& size, jobject surface);
84 }; 84 };
85 85
86 void MediaDecoderJob::Decode( 86 void MediaDecoderJob::Decode(
87 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params::AccessUnit& unit, 87 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params::AccessUnit& unit,
88 const base::Time& start_wallclock_time, 88 const base::TimeTicks& start_wallclock_time,
89 const base::TimeDelta& start_presentation_timestamp, 89 const base::TimeDelta& start_presentation_timestamp,
90 const MediaDecoderJob::DecoderCallback& callback) { 90 const MediaDecoderJob::DecoderCallback& callback) {
91 DCHECK(!decoding_); 91 DCHECK(!decoding_);
92 decoding_ = true; 92 decoding_ = true;
93 thread_->message_loop()->PostTask(FROM_HERE, base::Bind( 93 thread_->message_loop()->PostTask(FROM_HERE, base::Bind(
94 &MediaDecoderJob::DecodeInternal, base::Unretained(this), unit, 94 &MediaDecoderJob::DecodeInternal, base::Unretained(this), unit,
95 start_wallclock_time, start_presentation_timestamp, needs_flush_, 95 start_wallclock_time, start_presentation_timestamp, needs_flush_,
96 callback)); 96 callback));
97 needs_flush_ = false; 97 needs_flush_ = false;
98 } 98 }
99 99
100 void MediaDecoderJob::DecodeInternal( 100 void MediaDecoderJob::DecodeInternal(
101 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params::AccessUnit& unit, 101 const MediaPlayerHostMsg_ReadFromDemuxerAck_Params::AccessUnit& unit,
102 const base::Time& start_wallclock_time, 102 const base::TimeTicks& start_wallclock_time,
103 const base::TimeDelta& start_presentation_timestamp, 103 const base::TimeDelta& start_presentation_timestamp,
104 bool needs_flush, 104 bool needs_flush,
105 const MediaDecoderJob::DecoderCallback& callback) { 105 const MediaDecoderJob::DecoderCallback& callback) {
106 if (needs_flush) 106 if (needs_flush)
107 media_codec_bridge_->Reset(); 107 media_codec_bridge_->Reset();
108 base::TimeDelta timeout = base::TimeDelta::FromMicroseconds( 108 base::TimeDelta timeout = base::TimeDelta::FromMicroseconds(
109 kMediaCodecTimeoutInMicroseconds); 109 kMediaCodecTimeoutInMicroseconds);
110 int input_buf_index = media_codec_bridge_->DequeueInputBuffer(timeout); 110 int input_buf_index = media_codec_bridge_->DequeueInputBuffer(timeout);
111 if (input_buf_index == MediaCodecBridge::INFO_MEDIA_CODEC_ERROR) { 111 if (input_buf_index == MediaCodecBridge::INFO_MEDIA_CODEC_ERROR) {
112 message_loop_->PostTask(FROM_HERE, base::Bind( 112 message_loop_->PostTask(FROM_HERE, base::Bind(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 break; 144 break;
145 case MediaCodecBridge::INFO_MEDIA_CODEC_ERROR: 145 case MediaCodecBridge::INFO_MEDIA_CODEC_ERROR:
146 decode_status = DECODE_FAILED; 146 decode_status = DECODE_FAILED;
147 break; 147 break;
148 default: 148 default:
149 DCHECK_LE(0, outputBufferIndex); 149 DCHECK_LE(0, outputBufferIndex);
150 if (size == 0 && end_of_stream) 150 if (size == 0 && end_of_stream)
151 break; 151 break;
152 base::TimeDelta time_to_render; 152 base::TimeDelta time_to_render;
153 if (!start_wallclock_time.is_null()) { 153 if (!start_wallclock_time.is_null()) {
154 time_to_render = presentation_timestamp - (base::Time::Now() - 154 time_to_render = presentation_timestamp - (base::TimeTicks::Now() -
155 start_wallclock_time + start_presentation_timestamp); 155 start_wallclock_time + start_presentation_timestamp);
156 } 156 }
157 if (time_to_render >= base::TimeDelta()) { 157 if (time_to_render >= base::TimeDelta()) {
158 base::MessageLoop::current()->PostDelayedTask( 158 base::MessageLoop::current()->PostDelayedTask(
159 FROM_HERE, 159 FROM_HERE,
160 base::Bind(&MediaDecoderJob::ReleaseOutputBuffer, 160 base::Bind(&MediaDecoderJob::ReleaseOutputBuffer,
161 weak_this_.GetWeakPtr(), outputBufferIndex, size, 161 weak_this_.GetWeakPtr(), outputBufferIndex, size,
162 presentation_timestamp, end_of_stream, callback), 162 presentation_timestamp, end_of_stream, callback),
163 time_to_render); 163 time_to_render);
164 } else { 164 } else {
(...skipping 16 matching lines...) Expand all
181 const base::TimeDelta& presentation_timestamp, 181 const base::TimeDelta& presentation_timestamp,
182 bool end_of_stream, const MediaDecoderJob::DecoderCallback& callback) { 182 bool end_of_stream, const MediaDecoderJob::DecoderCallback& callback) {
183 // TODO(qinmin): Refactor this function. Maybe AudioDecoderJob should provide 183 // TODO(qinmin): Refactor this function. Maybe AudioDecoderJob should provide
184 // its own ReleaseOutputBuffer(). 184 // its own ReleaseOutputBuffer().
185 if (is_audio_) { 185 if (is_audio_) {
186 static_cast<AudioCodecBridge*>(media_codec_bridge_.get())->PlayOutputBuffer( 186 static_cast<AudioCodecBridge*>(media_codec_bridge_.get())->PlayOutputBuffer(
187 outputBufferIndex, size); 187 outputBufferIndex, size);
188 } 188 }
189 media_codec_bridge_->ReleaseOutputBuffer(outputBufferIndex, !is_audio_); 189 media_codec_bridge_->ReleaseOutputBuffer(outputBufferIndex, !is_audio_);
190 message_loop_->PostTask(FROM_HERE, base::Bind( 190 message_loop_->PostTask(FROM_HERE, base::Bind(
191 callback, DECODE_SUCCEEDED, presentation_timestamp, base::Time::Now(), 191 callback, DECODE_SUCCEEDED, presentation_timestamp,
192 end_of_stream)); 192 base::TimeTicks::Now(), end_of_stream));
193 } 193 }
194 194
195 void MediaDecoderJob::OnDecodeCompleted() { 195 void MediaDecoderJob::OnDecodeCompleted() {
196 decoding_ = false; 196 decoding_ = false;
197 } 197 }
198 198
199 void MediaDecoderJob::Flush() { 199 void MediaDecoderJob::Flush() {
200 // Do nothing, flush when the next Decode() happens. 200 // Do nothing, flush when the next Decode() happens.
201 needs_flush_ = true; 201 needs_flush_ = true;
202 } 202 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 playing_ = true; 293 playing_ = true;
294 294
295 CreateAudioDecoderJob(); 295 CreateAudioDecoderJob();
296 CreateVideoDecoderJob(); 296 CreateVideoDecoderJob();
297 297
298 StartInternal(); 298 StartInternal();
299 } 299 }
300 300
301 void MediaSourcePlayer::Pause() { 301 void MediaSourcePlayer::Pause() {
302 playing_ = false; 302 playing_ = false;
303 start_wallclock_time_ = base::Time(); 303 start_wallclock_time_ = base::TimeTicks();
304 } 304 }
305 305
306 bool MediaSourcePlayer::IsPlaying() { 306 bool MediaSourcePlayer::IsPlaying() {
307 return playing_; 307 return playing_;
308 } 308 }
309 309
310 int MediaSourcePlayer::GetVideoWidth() { 310 int MediaSourcePlayer::GetVideoWidth() {
311 return width_; 311 return width_;
312 } 312 }
313 313
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // Do nothing until the most recent seek request is processed. 442 // Do nothing until the most recent seek request is processed.
443 if (seek_request_id_ != seek_request_id) 443 if (seek_request_id_ != seek_request_id)
444 return; 444 return;
445 pending_event_ &= ~SEEK_EVENT_PENDING; 445 pending_event_ &= ~SEEK_EVENT_PENDING;
446 OnSeekComplete(); 446 OnSeekComplete();
447 ProcessPendingEvents(); 447 ProcessPendingEvents();
448 } 448 }
449 449
450 void MediaSourcePlayer::UpdateTimestamps( 450 void MediaSourcePlayer::UpdateTimestamps(
451 const base::TimeDelta& presentation_timestamp, 451 const base::TimeDelta& presentation_timestamp,
452 const base::Time& wallclock_time) { 452 const base::TimeTicks& wallclock_time) {
453 last_presentation_timestamp_ = presentation_timestamp; 453 last_presentation_timestamp_ = presentation_timestamp;
454 OnTimeUpdated(); 454 OnTimeUpdated();
455 if (start_wallclock_time_.is_null() && playing_) { 455 if (start_wallclock_time_.is_null() && playing_) {
456 start_wallclock_time_ = wallclock_time; 456 start_wallclock_time_ = wallclock_time;
457 start_presentation_timestamp_ = last_presentation_timestamp_; 457 start_presentation_timestamp_ = last_presentation_timestamp_;
458 } 458 }
459 } 459 }
460 460
461 void MediaSourcePlayer::ProcessPendingEvents() { 461 void MediaSourcePlayer::ProcessPendingEvents() {
462 // Wait for all the decoding jobs to finish before processing pending tasks. 462 // Wait for all the decoding jobs to finish before processing pending tasks.
463 if (active_decoding_tasks_ > 0) 463 if (active_decoding_tasks_ > 0)
464 return; 464 return;
465 465
466 if (pending_event_ & SEEK_EVENT_PENDING) { 466 if (pending_event_ & SEEK_EVENT_PENDING) {
467 ClearDecodingData(); 467 ClearDecodingData();
468 manager()->OnMediaSeekRequest( 468 manager()->OnMediaSeekRequest(
469 player_id(), last_presentation_timestamp_, ++seek_request_id_); 469 player_id(), last_presentation_timestamp_, ++seek_request_id_);
470 return; 470 return;
471 } 471 }
472 472
473 start_wallclock_time_ = base::Time(); 473 start_wallclock_time_ = base::TimeTicks();
474 if (pending_event_ & CONFIG_CHANGE_EVENT_PENDING) { 474 if (pending_event_ & CONFIG_CHANGE_EVENT_PENDING) {
475 DCHECK(reconfig_audio_decoder_ || reconfig_video_decoder_); 475 DCHECK(reconfig_audio_decoder_ || reconfig_video_decoder_);
476 manager()->OnMediaConfigRequest(player_id()); 476 manager()->OnMediaConfigRequest(player_id());
477 return; 477 return;
478 } 478 }
479 479
480 if (pending_event_ & SURFACE_CHANGE_EVENT_PENDING) { 480 if (pending_event_ & SURFACE_CHANGE_EVENT_PENDING) {
481 video_decoder_job_.reset(); 481 video_decoder_job_.reset();
482 CreateVideoDecoderJob(); 482 CreateVideoDecoderJob();
483 pending_event_ &= ~SURFACE_CHANGE_EVENT_PENDING; 483 pending_event_ &= ~SURFACE_CHANGE_EVENT_PENDING;
484 } 484 }
485 485
486 if (playing_ && pending_event_ == NO_EVENT_PENDING) 486 if (playing_ && pending_event_ == NO_EVENT_PENDING)
487 StartInternal(); 487 StartInternal();
488 } 488 }
489 489
490 void MediaSourcePlayer::MediaDecoderCallback( 490 void MediaSourcePlayer::MediaDecoderCallback(
491 bool is_audio, MediaDecoderJob::DecodeStatus decode_status, 491 bool is_audio, MediaDecoderJob::DecodeStatus decode_status,
492 const base::TimeDelta& presentation_timestamp, 492 const base::TimeDelta& presentation_timestamp,
493 const base::Time& wallclock_time, bool end_of_stream) { 493 const base::TimeTicks& wallclock_time, bool end_of_stream) {
494 if (active_decoding_tasks_ > 0) 494 if (active_decoding_tasks_ > 0)
495 active_decoding_tasks_--; 495 active_decoding_tasks_--;
496 496
497 if (is_audio && audio_decoder_job_) 497 if (is_audio && audio_decoder_job_)
498 audio_decoder_job_->OnDecodeCompleted(); 498 audio_decoder_job_->OnDecodeCompleted();
499 if (!is_audio && video_decoder_job_) 499 if (!is_audio && video_decoder_job_)
500 video_decoder_job_->OnDecodeCompleted(); 500 video_decoder_job_->OnDecodeCompleted();
501 501
502 if (decode_status == MediaDecoderJob::DECODE_FAILED) { 502 if (decode_status == MediaDecoderJob::DECODE_FAILED) {
503 Release(); 503 Release();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 594
595 595
596 void MediaSourcePlayer::PlaybackCompleted(bool is_audio) { 596 void MediaSourcePlayer::PlaybackCompleted(bool is_audio) {
597 if (is_audio) 597 if (is_audio)
598 audio_finished_ = true; 598 audio_finished_ = true;
599 else 599 else
600 video_finished_ = true; 600 video_finished_ = true;
601 601
602 if ((!HasAudio() || audio_finished_) && (!HasVideo() || video_finished_)) { 602 if ((!HasAudio() || audio_finished_) && (!HasVideo() || video_finished_)) {
603 playing_ = false; 603 playing_ = false;
604 start_wallclock_time_ = base::Time(); 604 start_wallclock_time_ = base::TimeTicks();
605 OnPlaybackComplete(); 605 OnPlaybackComplete();
606 } 606 }
607 } 607 }
608 608
609 void MediaSourcePlayer::ClearDecodingData() { 609 void MediaSourcePlayer::ClearDecodingData() {
610 if (audio_decoder_job_) 610 if (audio_decoder_job_)
611 audio_decoder_job_->Flush(); 611 audio_decoder_job_->Flush();
612 if (video_decoder_job_) 612 if (video_decoder_job_)
613 video_decoder_job_->Flush(); 613 video_decoder_job_->Flush();
614 start_wallclock_time_ = base::Time(); 614 start_wallclock_time_ = base::TimeTicks();
615 received_audio_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); 615 received_audio_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params();
616 received_video_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params(); 616 received_video_ = MediaPlayerHostMsg_ReadFromDemuxerAck_Params();
617 audio_access_unit_index_ = 0; 617 audio_access_unit_index_ = 0;
618 video_access_unit_index_ = 0; 618 video_access_unit_index_ = 0;
619 } 619 }
620 620
621 bool MediaSourcePlayer::HasVideo() { 621 bool MediaSourcePlayer::HasVideo() {
622 return kUnknownVideoCodec != video_codec_; 622 return kUnknownVideoCodec != video_codec_;
623 } 623 }
624 624
(...skipping 28 matching lines...) Expand all
653 reconfig_video_decoder_ = false; 653 reconfig_video_decoder_ = false;
654 } 654 }
655 655
656 // Inform the fullscreen view the player is ready. 656 // Inform the fullscreen view the player is ready.
657 // TODO(qinmin): refactor MediaPlayerBridge so that we have a better way 657 // TODO(qinmin): refactor MediaPlayerBridge so that we have a better way
658 // to inform ContentVideoView. 658 // to inform ContentVideoView.
659 OnMediaMetadataChanged(duration_, width_, height_, true); 659 OnMediaMetadataChanged(duration_, width_, height_, true);
660 } 660 }
661 661
662 } // namespace media 662 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_source_player.h ('k') | media/base/audio_renderer_mixer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698