| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/media/webmediaplayer_impl.h" | 5 #include "webkit/media/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 bool WebMediaPlayerImpl::supportsFullscreen() const { | 360 bool WebMediaPlayerImpl::supportsFullscreen() const { |
| 361 DCHECK(main_loop_->BelongsToCurrentThread()); | 361 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 362 return true; | 362 return true; |
| 363 } | 363 } |
| 364 | 364 |
| 365 bool WebMediaPlayerImpl::supportsSave() const { | 365 bool WebMediaPlayerImpl::supportsSave() const { |
| 366 DCHECK(main_loop_->BelongsToCurrentThread()); | 366 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 367 return supports_save_; | 367 return supports_save_; |
| 368 } | 368 } |
| 369 | 369 |
| 370 void WebMediaPlayerImpl::seekFloat(float seconds) { |
| 371 seek(seconds); |
| 372 } |
| 373 |
| 370 void WebMediaPlayerImpl::seek(float seconds) { | 374 void WebMediaPlayerImpl::seek(float seconds) { |
| 371 DCHECK(main_loop_->BelongsToCurrentThread()); | 375 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 372 | 376 |
| 373 if (starting_ || seeking_) { | 377 if (starting_ || seeking_) { |
| 374 pending_seek_ = true; | 378 pending_seek_ = true; |
| 375 pending_seek_seconds_ = seconds; | 379 pending_seek_seconds_ = seconds; |
| 376 if (chunk_demuxer_) | 380 if (chunk_demuxer_) |
| 377 chunk_demuxer_->CancelPendingSeek(); | 381 chunk_demuxer_->CancelPendingSeek(); |
| 378 return; | 382 return; |
| 379 } | 383 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 390 | 394 |
| 391 if (chunk_demuxer_) | 395 if (chunk_demuxer_) |
| 392 chunk_demuxer_->StartWaitingForSeek(); | 396 chunk_demuxer_->StartWaitingForSeek(); |
| 393 | 397 |
| 394 // Kick off the asynchronous seek! | 398 // Kick off the asynchronous seek! |
| 395 pipeline_->Seek( | 399 pipeline_->Seek( |
| 396 seek_time, | 400 seek_time, |
| 397 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek)); | 401 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek)); |
| 398 } | 402 } |
| 399 | 403 |
| 404 void WebMediaPlayerImpl::setEndTimeFloat(float seconds) { |
| 405 setEndTime(seconds); |
| 406 } |
| 407 |
| 400 void WebMediaPlayerImpl::setEndTime(float seconds) { | 408 void WebMediaPlayerImpl::setEndTime(float seconds) { |
| 401 DCHECK(main_loop_->BelongsToCurrentThread()); | 409 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 402 | 410 |
| 403 // TODO(hclam): add method call when it has been implemented. | 411 // TODO(hclam): add method call when it has been implemented. |
| 404 return; | 412 return; |
| 405 } | 413 } |
| 406 | 414 |
| 415 void WebMediaPlayerImpl::setRateFloat(float rate) { |
| 416 setRate(rate); |
| 417 } |
| 418 |
| 407 void WebMediaPlayerImpl::setRate(float rate) { | 419 void WebMediaPlayerImpl::setRate(float rate) { |
| 408 DCHECK(main_loop_->BelongsToCurrentThread()); | 420 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 409 | 421 |
| 410 // TODO(kylep): Remove when support for negatives is added. Also, modify the | 422 // TODO(kylep): Remove when support for negatives is added. Also, modify the |
| 411 // following checks so rewind uses reasonable values also. | 423 // following checks so rewind uses reasonable values also. |
| 412 if (rate < 0.0f) | 424 if (rate < 0.0f) |
| 413 return; | 425 return; |
| 414 | 426 |
| 415 // Limit rates to reasonable values by clamping. | 427 // Limit rates to reasonable values by clamping. |
| 416 if (rate != 0.0f) { | 428 if (rate != 0.0f) { |
| 417 if (rate < kMinRate) | 429 if (rate < kMinRate) |
| 418 rate = kMinRate; | 430 rate = kMinRate; |
| 419 else if (rate > kMaxRate) | 431 else if (rate > kMaxRate) |
| 420 rate = kMaxRate; | 432 rate = kMaxRate; |
| 421 } | 433 } |
| 422 | 434 |
| 423 playback_rate_ = rate; | 435 playback_rate_ = rate; |
| 424 if (!paused_) { | 436 if (!paused_) { |
| 425 pipeline_->SetPlaybackRate(rate); | 437 pipeline_->SetPlaybackRate(rate); |
| 426 } | 438 } |
| 427 } | 439 } |
| 428 | 440 |
| 441 void WebMediaPlayerImpl::setVolumeFloat(float volume) { |
| 442 setVolume(volume); |
| 443 } |
| 444 |
| 429 void WebMediaPlayerImpl::setVolume(float volume) { | 445 void WebMediaPlayerImpl::setVolume(float volume) { |
| 430 DCHECK(main_loop_->BelongsToCurrentThread()); | 446 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 431 | 447 |
| 432 pipeline_->SetVolume(volume); | 448 pipeline_->SetVolume(volume); |
| 433 } | 449 } |
| 434 | 450 |
| 435 void WebMediaPlayerImpl::setVisible(bool visible) { | 451 void WebMediaPlayerImpl::setVisible(bool visible) { |
| 436 DCHECK(main_loop_->BelongsToCurrentThread()); | 452 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 437 | 453 |
| 438 // TODO(hclam): add appropriate method call when pipeline has it implemented. | 454 // TODO(hclam): add appropriate method call when pipeline has it implemented. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 | 505 |
| 490 bool WebMediaPlayerImpl::seeking() const { | 506 bool WebMediaPlayerImpl::seeking() const { |
| 491 DCHECK(main_loop_->BelongsToCurrentThread()); | 507 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 492 | 508 |
| 493 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) | 509 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
| 494 return false; | 510 return false; |
| 495 | 511 |
| 496 return seeking_; | 512 return seeking_; |
| 497 } | 513 } |
| 498 | 514 |
| 515 float WebMediaPlayerImpl::durationFloat() const { |
| 516 return duration(); |
| 517 } |
| 518 |
| 499 float WebMediaPlayerImpl::duration() const { | 519 float WebMediaPlayerImpl::duration() const { |
| 500 DCHECK(main_loop_->BelongsToCurrentThread()); | 520 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 501 | 521 |
| 502 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) | 522 if (ready_state_ == WebMediaPlayer::ReadyStateHaveNothing) |
| 503 return std::numeric_limits<float>::quiet_NaN(); | 523 return std::numeric_limits<float>::quiet_NaN(); |
| 504 | 524 |
| 505 double duration; | 525 double duration; |
| 506 if (chunk_demuxer_) { | 526 if (chunk_demuxer_) { |
| 507 duration = chunk_demuxer_->GetDuration(); | 527 duration = chunk_demuxer_->GetDuration(); |
| 508 } else { | 528 } else { |
| 509 duration = GetPipelineDuration(); | 529 duration = GetPipelineDuration(); |
| 510 } | 530 } |
| 511 | 531 |
| 512 // Make sure super small durations don't get truncated to 0 and | 532 // Make sure super small durations don't get truncated to 0 and |
| 513 // large durations don't get converted to infinity by the double -> float | 533 // large durations don't get converted to infinity by the double -> float |
| 514 // conversion. | 534 // conversion. |
| 515 // | 535 // |
| 516 // TODO(acolwell): Remove when WebKit is changed to report duration as a | 536 // TODO(acolwell): Remove when WebKit is changed to report duration as a |
| 517 // double. | 537 // double. |
| 518 if (duration > 0.0 && duration < std::numeric_limits<double>::infinity()) { | 538 if (duration > 0.0 && duration < std::numeric_limits<double>::infinity()) { |
| 519 duration = std::max(duration, | 539 duration = std::max(duration, |
| 520 static_cast<double>(std::numeric_limits<float>::min())); | 540 static_cast<double>(std::numeric_limits<float>::min())); |
| 521 duration = std::min(duration, | 541 duration = std::min(duration, |
| 522 static_cast<double>(std::numeric_limits<float>::max())); | 542 static_cast<double>(std::numeric_limits<float>::max())); |
| 523 } | 543 } |
| 524 | 544 |
| 525 return static_cast<float>(duration); | 545 return static_cast<float>(duration); |
| 526 } | 546 } |
| 527 | 547 |
| 548 float WebMediaPlayerImpl::currentTimeFloat() const { |
| 549 return currentTime(); |
| 550 } |
| 551 |
| 528 float WebMediaPlayerImpl::currentTime() const { | 552 float WebMediaPlayerImpl::currentTime() const { |
| 529 DCHECK(main_loop_->BelongsToCurrentThread()); | 553 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 530 if (paused_) | 554 if (paused_) |
| 531 return static_cast<float>(paused_time_.InSecondsF()); | 555 return static_cast<float>(paused_time_.InSecondsF()); |
| 532 return static_cast<float>(pipeline_->GetMediaTime().InSecondsF()); | 556 return static_cast<float>(pipeline_->GetMediaTime().InSecondsF()); |
| 533 } | 557 } |
| 534 | 558 |
| 535 int WebMediaPlayerImpl::dataRate() const { | 559 int WebMediaPlayerImpl::dataRate() const { |
| 536 DCHECK(main_loop_->BelongsToCurrentThread()); | 560 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 537 | 561 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 550 } | 574 } |
| 551 | 575 |
| 552 const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() { | 576 const WebKit::WebTimeRanges& WebMediaPlayerImpl::buffered() { |
| 553 DCHECK(main_loop_->BelongsToCurrentThread()); | 577 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 554 WebKit::WebTimeRanges web_ranges( | 578 WebKit::WebTimeRanges web_ranges( |
| 555 ConvertToWebTimeRanges(pipeline_->GetBufferedTimeRanges())); | 579 ConvertToWebTimeRanges(pipeline_->GetBufferedTimeRanges())); |
| 556 buffered_.swap(web_ranges); | 580 buffered_.swap(web_ranges); |
| 557 return buffered_; | 581 return buffered_; |
| 558 } | 582 } |
| 559 | 583 |
| 584 float WebMediaPlayerImpl::maxTimeSeekableFloat() const { |
| 585 return maxTimeSeekable(); |
| 586 } |
| 587 |
| 560 float WebMediaPlayerImpl::maxTimeSeekable() const { | 588 float WebMediaPlayerImpl::maxTimeSeekable() const { |
| 561 DCHECK(main_loop_->BelongsToCurrentThread()); | 589 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 562 | 590 |
| 563 // If we haven't even gotten to ReadyStateHaveMetadata yet then just | 591 // If we haven't even gotten to ReadyStateHaveMetadata yet then just |
| 564 // return 0 so that the seekable range is empty. | 592 // return 0 so that the seekable range is empty. |
| 565 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) | 593 if (ready_state_ < WebMediaPlayer::ReadyStateHaveMetadata) |
| 566 return 0.0f; | 594 return 0.0f; |
| 567 | 595 |
| 568 // We don't support seeking in streaming media. | 596 // We don't support seeking in streaming media. |
| 569 if (data_source_ && data_source_->IsStreaming()) | 597 if (data_source_ && data_source_->IsStreaming()) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 656 |
| 629 WebMediaPlayer::MovieLoadType WebMediaPlayerImpl::movieLoadType() const { | 657 WebMediaPlayer::MovieLoadType WebMediaPlayerImpl::movieLoadType() const { |
| 630 DCHECK(main_loop_->BelongsToCurrentThread()); | 658 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 631 | 659 |
| 632 // Disable seeking while streaming. | 660 // Disable seeking while streaming. |
| 633 if (data_source_ && data_source_->IsStreaming()) | 661 if (data_source_ && data_source_->IsStreaming()) |
| 634 return WebMediaPlayer::MovieLoadTypeLiveStream; | 662 return WebMediaPlayer::MovieLoadTypeLiveStream; |
| 635 return WebMediaPlayer::MovieLoadTypeUnknown; | 663 return WebMediaPlayer::MovieLoadTypeUnknown; |
| 636 } | 664 } |
| 637 | 665 |
| 666 float WebMediaPlayerImpl::mediaTimeForTimeValueFloat(float timeValue) const { |
| 667 return mediaTimeForTimeValue(timeValue); |
| 668 } |
| 669 |
| 638 float WebMediaPlayerImpl::mediaTimeForTimeValue(float timeValue) const { | 670 float WebMediaPlayerImpl::mediaTimeForTimeValue(float timeValue) const { |
| 639 return ConvertSecondsToTimestamp(timeValue).InSecondsF(); | 671 return ConvertSecondsToTimestamp(timeValue).InSecondsF(); |
| 640 } | 672 } |
| 641 | 673 |
| 642 unsigned WebMediaPlayerImpl::decodedFrameCount() const { | 674 unsigned WebMediaPlayerImpl::decodedFrameCount() const { |
| 643 DCHECK(main_loop_->BelongsToCurrentThread()); | 675 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 644 | 676 |
| 645 media::PipelineStatistics stats = pipeline_->GetStatistics(); | 677 media::PipelineStatistics stats = pipeline_->GetStatistics(); |
| 646 return stats.video_frames_decoded; | 678 return stats.video_frames_decoded; |
| 647 } | 679 } |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 | 1266 |
| 1235 if (pending_repaint_) | 1267 if (pending_repaint_) |
| 1236 return; | 1268 return; |
| 1237 | 1269 |
| 1238 pending_repaint_ = true; | 1270 pending_repaint_ = true; |
| 1239 main_loop_->PostTask(FROM_HERE, base::Bind( | 1271 main_loop_->PostTask(FROM_HERE, base::Bind( |
| 1240 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); | 1272 &WebMediaPlayerImpl::Repaint, AsWeakPtr())); |
| 1241 } | 1273 } |
| 1242 | 1274 |
| 1243 } // namespace webkit_media | 1275 } // namespace webkit_media |
| OLD | NEW |