| 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 "media/base/pipeline.h" | 5 #include "media/base/pipeline.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 media_log_->CreateTimeEvent( | 296 media_log_->CreateTimeEvent( |
| 297 MediaLogEvent::DURATION_SET, "duration", duration)); | 297 MediaLogEvent::DURATION_SET, "duration", duration)); |
| 298 UMA_HISTOGRAM_LONG_TIMES("Media.Duration", duration); | 298 UMA_HISTOGRAM_LONG_TIMES("Media.Duration", duration); |
| 299 | 299 |
| 300 base::AutoLock auto_lock(lock_); | 300 base::AutoLock auto_lock(lock_); |
| 301 duration_ = duration; | 301 duration_ = duration; |
| 302 if (!duration_change_cb_.is_null()) | 302 if (!duration_change_cb_.is_null()) |
| 303 duration_change_cb_.Run(); | 303 duration_change_cb_.Run(); |
| 304 } | 304 } |
| 305 | 305 |
| 306 void Pipeline::OnStateTransition(PipelineStatus status) { | |
| 307 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 308 // Force post to process state transitions after current execution frame. | |
| 309 task_runner_->PostTask( | |
| 310 FROM_HERE, | |
| 311 base::Bind( | |
| 312 &Pipeline::StateTransitionTask, weak_factory_.GetWeakPtr(), status)); | |
| 313 } | |
| 314 | |
| 315 void Pipeline::StateTransitionTask(PipelineStatus status) { | 306 void Pipeline::StateTransitionTask(PipelineStatus status) { |
| 316 DCHECK(task_runner_->BelongsToCurrentThread()); | 307 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 317 | 308 |
| 318 // No-op any state transitions if we're stopping. | 309 // No-op any state transitions if we're stopping. |
| 319 if (state_ == kStopping || state_ == kStopped) | 310 if (state_ == kStopping || state_ == kStopped) |
| 320 return; | 311 return; |
| 321 | 312 |
| 322 // Preserve existing abnormal status, otherwise update based on the result of | 313 // Preserve existing abnormal status, otherwise update based on the result of |
| 323 // the previous operation. | 314 // the previous operation. |
| 324 status_ = (status_ != PIPELINE_OK ? status_ : status); | 315 status_ = (status_ != PIPELINE_OK ? status_ : status); |
| 325 | 316 |
| 326 if (status_ != PIPELINE_OK) { | 317 if (status_ != PIPELINE_OK) { |
| 327 ErrorChangedTask(status_); | 318 ErrorChangedTask(status_); |
| 328 return; | 319 return; |
| 329 } | 320 } |
| 330 | 321 |
| 331 // Guard against accidentally clearing |pending_callbacks_| for states that | 322 // Guard against accidentally clearing |pending_callbacks_| for states that |
| 332 // use it as well as states that should not be using it. | 323 // use it as well as states that should not be using it. |
| 333 DCHECK_EQ(pending_callbacks_.get() != NULL, state_ == kSeeking); | 324 DCHECK_EQ(pending_callbacks_.get() != NULL, state_ == kSeeking); |
| 334 | 325 |
| 335 pending_callbacks_.reset(); | 326 pending_callbacks_.reset(); |
| 336 | 327 |
| 337 PipelineStatusCB done_cb = | 328 PipelineStatusCB done_cb = |
| 338 base::Bind(&Pipeline::OnStateTransition, weak_factory_.GetWeakPtr()); | 329 base::Bind(&Pipeline::StateTransitionTask, weak_factory_.GetWeakPtr()); |
| 339 | 330 |
| 340 // Switch states, performing any entrance actions for the new state as well. | 331 // Switch states, performing any entrance actions for the new state as well. |
| 341 SetState(GetNextState()); | 332 SetState(GetNextState()); |
| 342 switch (state_) { | 333 switch (state_) { |
| 343 case kInitDemuxer: | 334 case kInitDemuxer: |
| 344 return InitializeDemuxer(done_cb); | 335 return InitializeDemuxer(done_cb); |
| 345 | 336 |
| 346 case kInitRenderer: | 337 case kInitRenderer: |
| 347 return InitializeRenderer(base::Bind(done_cb, PIPELINE_OK)); | 338 return InitializeRenderer(base::Bind(done_cb, PIPELINE_OK)); |
| 348 | 339 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 593 |
| 603 const base::TimeDelta seek_timestamp = | 594 const base::TimeDelta seek_timestamp = |
| 604 std::max(time, demuxer_->GetStartTime()); | 595 std::max(time, demuxer_->GetStartTime()); |
| 605 | 596 |
| 606 SetState(kSeeking); | 597 SetState(kSeeking); |
| 607 seek_cb_ = seek_cb; | 598 seek_cb_ = seek_cb; |
| 608 renderer_ended_ = false; | 599 renderer_ended_ = false; |
| 609 text_renderer_ended_ = false; | 600 text_renderer_ended_ = false; |
| 610 start_timestamp_ = seek_timestamp; | 601 start_timestamp_ = seek_timestamp; |
| 611 | 602 |
| 612 DoSeek(seek_timestamp, | 603 DoSeek(seek_timestamp, base::Bind(&Pipeline::StateTransitionTask, |
| 613 base::Bind(&Pipeline::OnStateTransition, weak_factory_.GetWeakPtr())); | 604 weak_factory_.GetWeakPtr())); |
| 614 } | 605 } |
| 615 | 606 |
| 616 void Pipeline::SetCdmTask(CdmContext* cdm_context, | 607 void Pipeline::SetCdmTask(CdmContext* cdm_context, |
| 617 const CdmAttachedCB& cdm_attached_cb) { | 608 const CdmAttachedCB& cdm_attached_cb) { |
| 618 if (!renderer_) { | 609 if (!renderer_) { |
| 619 pending_cdm_context_ = cdm_context; | 610 pending_cdm_context_ = cdm_context; |
| 620 cdm_attached_cb.Run(true); | 611 cdm_attached_cb.Run(true); |
| 621 return; | 612 return; |
| 622 } | 613 } |
| 623 | 614 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 metadata_cb_.Run(metadata); | 740 metadata_cb_.Run(metadata); |
| 750 } | 741 } |
| 751 | 742 |
| 752 void Pipeline::BufferingStateChanged(BufferingState new_buffering_state) { | 743 void Pipeline::BufferingStateChanged(BufferingState new_buffering_state) { |
| 753 DVLOG(1) << __FUNCTION__ << "(" << new_buffering_state << ") "; | 744 DVLOG(1) << __FUNCTION__ << "(" << new_buffering_state << ") "; |
| 754 DCHECK(task_runner_->BelongsToCurrentThread()); | 745 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 755 buffering_state_cb_.Run(new_buffering_state); | 746 buffering_state_cb_.Run(new_buffering_state); |
| 756 } | 747 } |
| 757 | 748 |
| 758 } // namespace media | 749 } // namespace media |
| OLD | NEW |