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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 540 |
541 void PipelineImpl::SetNaturalVideoSize(const gfx::Size& size) { | 541 void PipelineImpl::SetNaturalVideoSize(const gfx::Size& size) { |
542 DCHECK(IsRunning()); | 542 DCHECK(IsRunning()); |
543 media_log_->AddEvent(media_log_->CreateVideoSizeSetEvent( | 543 media_log_->AddEvent(media_log_->CreateVideoSizeSetEvent( |
544 size.width(), size.height())); | 544 size.width(), size.height())); |
545 | 545 |
546 base::AutoLock auto_lock(lock_); | 546 base::AutoLock auto_lock(lock_); |
547 natural_size_ = size; | 547 natural_size_ = size; |
548 } | 548 } |
549 | 549 |
550 void PipelineImpl::SetStreaming(bool streaming) { | |
551 DCHECK(IsRunning()); | |
552 media_log_->AddEvent( | |
553 media_log_->CreateBooleanEvent( | |
554 MediaLogEvent::STREAMING_SET, "streaming", streaming)); | |
555 | |
556 base::AutoLock auto_lock(lock_); | |
557 streaming_ = streaming; | |
558 } | |
559 | |
560 void PipelineImpl::NotifyEnded() { | 550 void PipelineImpl::NotifyEnded() { |
561 DCHECK(IsRunning()); | 551 DCHECK(IsRunning()); |
562 message_loop_->PostTask(FROM_HERE, | 552 message_loop_->PostTask(FROM_HERE, |
563 base::Bind(&PipelineImpl::NotifyEndedTask, this)); | 553 base::Bind(&PipelineImpl::NotifyEndedTask, this)); |
564 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::ENDED)); | 554 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::ENDED)); |
565 } | 555 } |
566 | 556 |
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) { | 557 void PipelineImpl::SetNetworkActivity(bool is_downloading_data) { |
579 DCHECK(IsRunning()); | 558 DCHECK(IsRunning()); |
580 | 559 |
581 NetworkEvent type = DOWNLOAD_PAUSED; | 560 NetworkEvent type = DOWNLOAD_PAUSED; |
582 if (is_downloading_data) | 561 if (is_downloading_data) |
583 type = DOWNLOAD_CONTINUED; | 562 type = DOWNLOAD_CONTINUED; |
584 | 563 |
585 { | 564 { |
586 base::AutoLock auto_lock(lock_); | 565 base::AutoLock auto_lock(lock_); |
587 download_rate_monitor_.SetNetworkActivity(is_downloading_data); | 566 download_rate_monitor_.SetNetworkActivity(is_downloading_data); |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 | 1016 |
1038 base::AutoLock auto_lock(lock_); | 1017 base::AutoLock auto_lock(lock_); |
1039 // We use audio stream to update the clock. So if there is such a stream, | 1018 // 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. | 1019 // we pause the clock until we receive a valid timestamp. |
1041 waiting_for_clock_update_ = has_audio_; | 1020 waiting_for_clock_update_ = has_audio_; |
1042 if (!waiting_for_clock_update_) | 1021 if (!waiting_for_clock_update_) |
1043 clock_->Play(); | 1022 clock_->Play(); |
1044 | 1023 |
1045 // Start monitoring rate of downloading. | 1024 // Start monitoring rate of downloading. |
1046 int bitrate = 0; | 1025 int bitrate = 0; |
1047 if (demuxer_.get()) | 1026 if (demuxer_.get()) { |
1048 bitrate = demuxer_->GetBitrate(); | 1027 bitrate = demuxer_->GetBitrate(); |
| 1028 local_source_ = demuxer_->IsLocalSource(); |
| 1029 streaming_ = !demuxer_->IsSeekable(); |
| 1030 } |
1049 // Needs to be locked because most other calls to |download_rate_monitor_| | 1031 // Needs to be locked because most other calls to |download_rate_monitor_| |
1050 // occur on the renderer thread. | 1032 // occur on the renderer thread. |
1051 download_rate_monitor_.Start( | 1033 download_rate_monitor_.Start( |
1052 base::Bind(&PipelineImpl::OnCanPlayThrough, this), bitrate); | 1034 base::Bind(&PipelineImpl::OnCanPlayThrough, this), |
| 1035 bitrate, streaming_, local_source_); |
1053 download_rate_monitor_.SetBufferedBytes(buffered_bytes_, base::Time::Now()); | 1036 download_rate_monitor_.SetBufferedBytes(buffered_bytes_, base::Time::Now()); |
1054 | 1037 |
1055 if (IsPipelineStopPending()) { | 1038 if (IsPipelineStopPending()) { |
1056 // We had a pending stop request need to be honored right now. | 1039 // We had a pending stop request need to be honored right now. |
1057 TearDownPipeline(); | 1040 TearDownPipeline(); |
1058 } | 1041 } |
1059 } else { | 1042 } else { |
1060 NOTREACHED() << "Unexpected state: " << state_; | 1043 NOTREACHED() << "Unexpected state: " << state_; |
1061 } | 1044 } |
1062 } | 1045 } |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 message_loop_->PostTask(FROM_HERE, | 1414 message_loop_->PostTask(FROM_HERE, |
1432 base::Bind(&PipelineImpl::NotifyCanPlayThrough, this)); | 1415 base::Bind(&PipelineImpl::NotifyCanPlayThrough, this)); |
1433 } | 1416 } |
1434 | 1417 |
1435 void PipelineImpl::NotifyCanPlayThrough() { | 1418 void PipelineImpl::NotifyCanPlayThrough() { |
1436 DCHECK_EQ(MessageLoop::current(), message_loop_); | 1419 DCHECK_EQ(MessageLoop::current(), message_loop_); |
1437 NotifyNetworkEventTask(CAN_PLAY_THROUGH); | 1420 NotifyNetworkEventTask(CAN_PLAY_THROUGH); |
1438 } | 1421 } |
1439 | 1422 |
1440 } // namespace media | 1423 } // namespace media |
OLD | NEW |