| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/filters/pipeline_controller.h" | 5 #include "media/filters/pipeline_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "media/base/demuxer.h" | 8 #include "media/base/demuxer.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 PipelineController::PipelineController( | 12 PipelineController::PipelineController( |
| 13 Pipeline* pipeline, | 13 Pipeline* pipeline, |
| 14 const RendererFactoryCB& renderer_factory_cb, | 14 const RendererFactoryCB& renderer_factory_cb, |
| 15 const SeekedCB& seeked_cb, | 15 const SeekedCB& seeked_cb, |
| 16 const SuspendedCB& suspended_cb, | 16 const SuspendedCB& suspended_cb, |
| 17 const BeforeResumeCB& before_resume_cb, |
| 18 const ResumedCB& resumed_cb, |
| 17 const PipelineStatusCB& error_cb) | 19 const PipelineStatusCB& error_cb) |
| 18 : pipeline_(pipeline), | 20 : pipeline_(pipeline), |
| 19 renderer_factory_cb_(renderer_factory_cb), | 21 renderer_factory_cb_(renderer_factory_cb), |
| 20 seeked_cb_(seeked_cb), | 22 seeked_cb_(seeked_cb), |
| 21 suspended_cb_(suspended_cb), | 23 suspended_cb_(suspended_cb), |
| 24 before_resume_cb_(before_resume_cb), |
| 25 resumed_cb_(resumed_cb), |
| 22 error_cb_(error_cb), | 26 error_cb_(error_cb), |
| 23 weak_factory_(this) { | 27 weak_factory_(this) { |
| 24 DCHECK(pipeline_); | 28 DCHECK(pipeline_); |
| 25 DCHECK(!renderer_factory_cb_.is_null()); | 29 DCHECK(!renderer_factory_cb_.is_null()); |
| 26 DCHECK(!seeked_cb_.is_null()); | 30 DCHECK(!seeked_cb_.is_null()); |
| 27 DCHECK(!suspended_cb_.is_null()); | 31 DCHECK(!suspended_cb_.is_null()); |
| 32 DCHECK(!before_resume_cb_.is_null()); |
| 33 DCHECK(!resumed_cb_.is_null()); |
| 28 DCHECK(!error_cb_.is_null()); | 34 DCHECK(!error_cb_.is_null()); |
| 29 } | 35 } |
| 30 | 36 |
| 31 PipelineController::~PipelineController() { | 37 PipelineController::~PipelineController() { |
| 32 DCHECK(thread_checker_.CalledOnValidThread()); | 38 DCHECK(thread_checker_.CalledOnValidThread()); |
| 33 } | 39 } |
| 34 | 40 |
| 35 // TODO(sandersd): If there is a pending suspend, don't call pipeline_.Start() | 41 // TODO(sandersd): If there is a pending suspend, don't call pipeline_.Start() |
| 36 // until Resume(). | 42 // until Resume(). |
| 37 void PipelineController::Start(Demuxer* demuxer, | 43 void PipelineController::Start(Demuxer* demuxer, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 122 |
| 117 void PipelineController::OnPipelineStatus(State state, | 123 void PipelineController::OnPipelineStatus(State state, |
| 118 PipelineStatus pipeline_status) { | 124 PipelineStatus pipeline_status) { |
| 119 DCHECK(thread_checker_.CalledOnValidThread()); | 125 DCHECK(thread_checker_.CalledOnValidThread()); |
| 120 | 126 |
| 121 if (pipeline_status != PIPELINE_OK) { | 127 if (pipeline_status != PIPELINE_OK) { |
| 122 error_cb_.Run(pipeline_status); | 128 error_cb_.Run(pipeline_status); |
| 123 return; | 129 return; |
| 124 } | 130 } |
| 125 | 131 |
| 132 State old_state = state_; |
| 126 state_ = state; | 133 state_ = state; |
| 127 | 134 |
| 128 if (state == State::PLAYING) { | 135 if (state == State::PLAYING) { |
| 129 // Start(), Seek(), or Resume() completed; we can be sure that | 136 // Start(), Seek(), or Resume() completed; we can be sure that |
| 130 // |demuxer_| got the seek it was waiting for. | 137 // |demuxer_| got the seek it was waiting for. |
| 131 waiting_for_seek_ = false; | 138 waiting_for_seek_ = false; |
| 139 |
| 140 // TODO(avayvod): Remove resumed callback after https://crbug.com/678374 is |
| 141 // properly fixed. |
| 142 if (old_state == State::RESUMING) |
| 143 resumed_cb_.Run(); |
| 132 } else if (state == State::SUSPENDED) { | 144 } else if (state == State::SUSPENDED) { |
| 133 // Warning: possibly reentrant. The state may change inside this callback. | 145 // Warning: possibly reentrant. The state may change inside this callback. |
| 134 // It must be safe to call Dispatch() twice in a row here. | 146 // It must be safe to call Dispatch() twice in a row here. |
| 135 suspended_cb_.Run(); | 147 suspended_cb_.Run(); |
| 136 } | 148 } |
| 137 | 149 |
| 138 Dispatch(); | 150 Dispatch(); |
| 139 } | 151 } |
| 140 | 152 |
| 141 // Note: Dispatch() may be called re-entrantly (by callbacks internally) or | 153 // Note: Dispatch() may be called re-entrantly (by callbacks internally) or |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 pending_time_updated_ = true; | 185 pending_time_updated_ = true; |
| 174 } | 186 } |
| 175 | 187 |
| 176 // Tell |demuxer_| to expect our resume. | 188 // Tell |demuxer_| to expect our resume. |
| 177 DCHECK(!waiting_for_seek_); | 189 DCHECK(!waiting_for_seek_); |
| 178 waiting_for_seek_ = true; | 190 waiting_for_seek_ = true; |
| 179 demuxer_->StartWaitingForSeek(seek_time_); | 191 demuxer_->StartWaitingForSeek(seek_time_); |
| 180 | 192 |
| 181 pending_resume_ = false; | 193 pending_resume_ = false; |
| 182 state_ = State::RESUMING; | 194 state_ = State::RESUMING; |
| 195 before_resume_cb_.Run(); |
| 183 pipeline_->Resume(renderer_factory_cb_.Run(), seek_time_, | 196 pipeline_->Resume(renderer_factory_cb_.Run(), seek_time_, |
| 184 base::Bind(&PipelineController::OnPipelineStatus, | 197 base::Bind(&PipelineController::OnPipelineStatus, |
| 185 weak_factory_.GetWeakPtr(), State::PLAYING)); | 198 weak_factory_.GetWeakPtr(), State::PLAYING)); |
| 186 return; | 199 return; |
| 187 } | 200 } |
| 188 | 201 |
| 189 // If we have pending operations, and a seek is ongoing, abort it. | 202 // If we have pending operations, and a seek is ongoing, abort it. |
| 190 if ((pending_seek_ || pending_suspend_) && waiting_for_seek_) { | 203 if ((pending_seek_ || pending_suspend_) && waiting_for_seek_) { |
| 191 // If there is no pending seek, return the current seek to pending status. | 204 // If there is no pending seek, return the current seek to pending status. |
| 192 if (!pending_seek_) { | 205 if (!pending_seek_) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 pending_seeked_cb_ = false; | 240 pending_seeked_cb_ = false; |
| 228 bool was_pending_time_updated = pending_time_updated_; | 241 bool was_pending_time_updated = pending_time_updated_; |
| 229 pending_time_updated_ = false; | 242 pending_time_updated_ = false; |
| 230 seeked_cb_.Run(was_pending_time_updated); | 243 seeked_cb_.Run(was_pending_time_updated); |
| 231 return; | 244 return; |
| 232 } | 245 } |
| 233 } | 246 } |
| 234 } | 247 } |
| 235 | 248 |
| 236 } // namespace media | 249 } // namespace media |
| OLD | NEW |