Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // TODO(scherkus): clean up PipelineImpl... too many crazy function names, | 5 // TODO(scherkus): clean up PipelineImpl... too many crazy function names, |
| 6 // potential deadlocks, etc... | 6 // potential deadlocks, etc... |
| 7 | 7 |
| 8 #include "media/base/pipeline_impl.h" | 8 #include "media/base/pipeline_impl.h" |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 if (state_ == kEnded || elapsed > duration_) { | 244 if (state_ == kEnded || elapsed > duration_) { |
| 245 return duration_; | 245 return duration_; |
| 246 } | 246 } |
| 247 return elapsed; | 247 return elapsed; |
| 248 } | 248 } |
| 249 | 249 |
| 250 base::TimeDelta PipelineImpl::GetBufferedTime() { | 250 base::TimeDelta PipelineImpl::GetBufferedTime() { |
| 251 base::AutoLock auto_lock(lock_); | 251 base::AutoLock auto_lock(lock_); |
| 252 | 252 |
| 253 // If media is fully loaded, then return duration. | 253 // If media is fully loaded, then return duration. |
| 254 if (loaded_ || total_bytes_ == buffered_bytes_) { | 254 if (local_source_ || total_bytes_ == buffered_bytes_) { |
| 255 max_buffered_time_ = duration_; | 255 max_buffered_time_ = duration_; |
| 256 return duration_; | 256 return duration_; |
| 257 } | 257 } |
| 258 | 258 |
| 259 base::TimeDelta current_time = GetCurrentTime_Locked(); | 259 base::TimeDelta current_time = GetCurrentTime_Locked(); |
| 260 | 260 |
| 261 // If buffered time was set, we report that value directly. | 261 // If buffered time was set, we report that value directly. |
| 262 if (buffered_time_.ToInternalValue() > 0) | 262 if (buffered_time_.ToInternalValue() > 0) |
| 263 return std::max(buffered_time_, current_time); | 263 return std::max(buffered_time_, current_time); |
| 264 | 264 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 CHECK(out_size); | 305 CHECK(out_size); |
| 306 base::AutoLock auto_lock(lock_); | 306 base::AutoLock auto_lock(lock_); |
| 307 *out_size = natural_size_; | 307 *out_size = natural_size_; |
| 308 } | 308 } |
| 309 | 309 |
| 310 bool PipelineImpl::IsStreaming() const { | 310 bool PipelineImpl::IsStreaming() const { |
| 311 base::AutoLock auto_lock(lock_); | 311 base::AutoLock auto_lock(lock_); |
| 312 return streaming_; | 312 return streaming_; |
| 313 } | 313 } |
| 314 | 314 |
| 315 bool PipelineImpl::IsLoaded() const { | 315 bool PipelineImpl::IsLocalSource() const { |
| 316 base::AutoLock auto_lock(lock_); | 316 base::AutoLock auto_lock(lock_); |
| 317 return loaded_; | 317 return local_source_; |
| 318 } | 318 } |
| 319 | 319 |
| 320 PipelineStatistics PipelineImpl::GetStatistics() const { | 320 PipelineStatistics PipelineImpl::GetStatistics() const { |
| 321 base::AutoLock auto_lock(lock_); | 321 base::AutoLock auto_lock(lock_); |
| 322 return statistics_; | 322 return statistics_; |
| 323 } | 323 } |
| 324 | 324 |
| 325 void PipelineImpl::SetClockForTesting(Clock* clock) { | 325 void PipelineImpl::SetClockForTesting(Clock* clock) { |
| 326 clock_.reset(clock); | 326 clock_.reset(clock); |
| 327 } | 327 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 351 running_ = false; | 351 running_ = false; |
| 352 stop_pending_ = false; | 352 stop_pending_ = false; |
| 353 seek_pending_ = false; | 353 seek_pending_ = false; |
| 354 tearing_down_ = false; | 354 tearing_down_ = false; |
| 355 error_caused_teardown_ = false; | 355 error_caused_teardown_ = false; |
| 356 playback_rate_change_pending_ = false; | 356 playback_rate_change_pending_ = false; |
| 357 duration_ = kZero; | 357 duration_ = kZero; |
| 358 buffered_time_ = kZero; | 358 buffered_time_ = kZero; |
| 359 buffered_bytes_ = 0; | 359 buffered_bytes_ = 0; |
| 360 streaming_ = false; | 360 streaming_ = false; |
| 361 loaded_ = false; | 361 local_source_ = false; |
| 362 total_bytes_ = 0; | 362 total_bytes_ = 0; |
| 363 natural_size_.SetSize(0, 0); | 363 natural_size_.SetSize(0, 0); |
| 364 volume_ = 1.0f; | 364 volume_ = 1.0f; |
| 365 preload_ = AUTO; | 365 preload_ = AUTO; |
| 366 playback_rate_ = 0.0f; | 366 playback_rate_ = 0.0f; |
| 367 pending_playback_rate_ = 0.0f; | 367 pending_playback_rate_ = 0.0f; |
| 368 status_ = PIPELINE_OK; | 368 status_ = PIPELINE_OK; |
| 369 has_audio_ = false; | 369 has_audio_ = false; |
| 370 has_video_ = false; | 370 has_video_ = false; |
| 371 waiting_for_clock_update_ = false; | 371 waiting_for_clock_update_ = false; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 } | 548 } |
| 549 | 549 |
| 550 void PipelineImpl::SetStreaming(bool streaming) { | 550 void PipelineImpl::SetStreaming(bool streaming) { |
| 551 DCHECK(IsRunning()); | 551 DCHECK(IsRunning()); |
| 552 media_log_->AddEvent( | 552 media_log_->AddEvent( |
| 553 media_log_->CreateBooleanEvent( | 553 media_log_->CreateBooleanEvent( |
| 554 MediaLogEvent::STREAMING_SET, "streaming", streaming)); | 554 MediaLogEvent::STREAMING_SET, "streaming", streaming)); |
| 555 | 555 |
| 556 base::AutoLock auto_lock(lock_); | 556 base::AutoLock auto_lock(lock_); |
| 557 streaming_ = streaming; | 557 streaming_ = streaming; |
| 558 download_rate_monitor_.set_streaming(streaming_); | |
| 558 } | 559 } |
| 559 | 560 |
| 560 void PipelineImpl::NotifyEnded() { | 561 void PipelineImpl::NotifyEnded() { |
| 561 DCHECK(IsRunning()); | 562 DCHECK(IsRunning()); |
| 562 message_loop_->PostTask(FROM_HERE, | 563 message_loop_->PostTask(FROM_HERE, |
| 563 base::Bind(&PipelineImpl::NotifyEndedTask, this)); | 564 base::Bind(&PipelineImpl::NotifyEndedTask, this)); |
| 564 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::ENDED)); | 565 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::ENDED)); |
| 565 } | 566 } |
| 566 | 567 |
| 567 void PipelineImpl::SetLoaded(bool loaded) { | |
| 568 DCHECK(IsRunning()); | |
| 569 media_log_->AddEvent( | |
| 570 media_log_->CreateBooleanEvent( | |
| 571 MediaLogEvent::LOADED_SET, "loaded", loaded)); | |
| 572 | |
| 573 base::AutoLock auto_lock(lock_); | |
| 574 loaded_ = loaded; | |
| 575 download_rate_monitor_.set_loaded(loaded_); | |
| 576 } | |
| 577 | |
| 578 void PipelineImpl::SetNetworkActivity(bool is_downloading_data) { | 568 void PipelineImpl::SetNetworkActivity(bool is_downloading_data) { |
| 579 DCHECK(IsRunning()); | 569 DCHECK(IsRunning()); |
| 580 | 570 |
| 581 NetworkEvent type = DOWNLOAD_PAUSED; | 571 NetworkEvent type = DOWNLOAD_PAUSED; |
| 582 if (is_downloading_data) | 572 if (is_downloading_data) |
| 583 type = DOWNLOAD_CONTINUED; | 573 type = DOWNLOAD_CONTINUED; |
| 584 | 574 |
| 585 { | 575 { |
| 586 base::AutoLock auto_lock(lock_); | 576 base::AutoLock auto_lock(lock_); |
| 587 download_rate_monitor_.SetNetworkActivity(is_downloading_data); | 577 download_rate_monitor_.SetNetworkActivity(is_downloading_data); |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1037 | 1027 |
| 1038 base::AutoLock auto_lock(lock_); | 1028 base::AutoLock auto_lock(lock_); |
| 1039 // We use audio stream to update the clock. So if there is such a stream, | 1029 // We use audio stream to update the clock. So if there is such a stream, |
| 1040 // we pause the clock until we receive a valid timestamp. | 1030 // we pause the clock until we receive a valid timestamp. |
| 1041 waiting_for_clock_update_ = has_audio_; | 1031 waiting_for_clock_update_ = has_audio_; |
| 1042 if (!waiting_for_clock_update_) | 1032 if (!waiting_for_clock_update_) |
| 1043 clock_->Play(); | 1033 clock_->Play(); |
| 1044 | 1034 |
| 1045 // Start monitoring rate of downloading. | 1035 // Start monitoring rate of downloading. |
| 1046 int bitrate = 0; | 1036 int bitrate = 0; |
| 1047 if (demuxer_.get()) | 1037 if (demuxer_.get()) { |
| 1048 bitrate = demuxer_->GetBitrate(); | 1038 bitrate = demuxer_->GetBitrate(); |
| 1039 local_source_ = demuxer_->IsLocalSource(); | |
| 1040 download_rate_monitor_.set_local_source(local_source_); | |
|
acolwell GONE FROM CHROMIUM
2011/11/30 19:26:11
Consider making local_source a parameter of the St
vrk (LEFT CHROMIUM)
2011/12/01 02:11:35
Done.
| |
| 1041 } | |
| 1049 // Needs to be locked because most other calls to |download_rate_monitor_| | 1042 // Needs to be locked because most other calls to |download_rate_monitor_| |
| 1050 // occur on the renderer thread. | 1043 // occur on the renderer thread. |
| 1051 download_rate_monitor_.Start( | 1044 download_rate_monitor_.Start( |
| 1052 base::Bind(&PipelineImpl::OnCanPlayThrough, this), bitrate); | 1045 base::Bind(&PipelineImpl::OnCanPlayThrough, this), bitrate); |
| 1053 download_rate_monitor_.SetBufferedBytes(buffered_bytes_, base::Time::Now()); | 1046 download_rate_monitor_.SetBufferedBytes(buffered_bytes_, base::Time::Now()); |
| 1054 | 1047 |
| 1055 if (IsPipelineStopPending()) { | 1048 if (IsPipelineStopPending()) { |
| 1056 // We had a pending stop request need to be honored right now. | 1049 // We had a pending stop request need to be honored right now. |
| 1057 TearDownPipeline(); | 1050 TearDownPipeline(); |
| 1058 } | 1051 } |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1431 message_loop_->PostTask(FROM_HERE, | 1424 message_loop_->PostTask(FROM_HERE, |
| 1432 base::Bind(&PipelineImpl::NotifyCanPlayThrough, this)); | 1425 base::Bind(&PipelineImpl::NotifyCanPlayThrough, this)); |
| 1433 } | 1426 } |
| 1434 | 1427 |
| 1435 void PipelineImpl::NotifyCanPlayThrough() { | 1428 void PipelineImpl::NotifyCanPlayThrough() { |
| 1436 DCHECK_EQ(MessageLoop::current(), message_loop_); | 1429 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 1437 NotifyNetworkEventTask(CAN_PLAY_THROUGH); | 1430 NotifyNetworkEventTask(CAN_PLAY_THROUGH); |
| 1438 } | 1431 } |
| 1439 | 1432 |
| 1440 } // namespace media | 1433 } // namespace media |
| OLD | NEW |