| 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 #include "media/base/composite_filter.h" | 5 #include "media/base/composite_filter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 DCHECK_EQ(message_loop_, MessageLoop::current()); | 62 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 63 if (!filter.get() || state_ != kCreated || !host()) | 63 if (!filter.get() || state_ != kCreated || !host()) |
| 64 return false; | 64 return false; |
| 65 | 65 |
| 66 // Register ourselves as the filter's host. | 66 // Register ourselves as the filter's host. |
| 67 filter->set_host(host_impl_.get()); | 67 filter->set_host(host_impl_.get()); |
| 68 filters_.push_back(make_scoped_refptr(filter.get())); | 68 filters_.push_back(make_scoped_refptr(filter.get())); |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool CompositeFilter::RemoveFilter(scoped_refptr<Filter> filter) { |
| 73 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 74 if (!filter.get() || state_ != kCreated || !host()) |
| 75 return false; |
| 76 |
| 77 bool found = false; |
| 78 for (FilterVector::iterator it = filters_.begin(); |
| 79 it != filters_.end() && !found; ++it) { |
| 80 if (it->get() == filter.get()) { |
| 81 filters_.erase(it); |
| 82 found = true; |
| 83 } |
| 84 } |
| 85 filter->clear_host(); |
| 86 |
| 87 if (!found) |
| 88 return false; |
| 89 |
| 90 return true; |
| 91 } |
| 92 |
| 72 void CompositeFilter::set_host(FilterHost* host) { | 93 void CompositeFilter::set_host(FilterHost* host) { |
| 73 DCHECK_EQ(message_loop_, MessageLoop::current()); | 94 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 74 DCHECK(host); | 95 DCHECK(host); |
| 75 DCHECK(!host_impl_.get()); | 96 DCHECK(!host_impl_.get()); |
| 76 host_impl_.reset(new FilterHostImpl(this, host)); | 97 host_impl_.reset(new FilterHostImpl(this, host)); |
| 77 } | 98 } |
| 78 | 99 |
| 79 FilterHost* CompositeFilter::host() { | 100 FilterHost* CompositeFilter::host() { |
| 80 return host_impl_.get() ? host_impl_->host() : NULL; | 101 return host_impl_.get() ? host_impl_->host() : NULL; |
| 81 } | 102 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 353 } |
| 333 | 354 |
| 334 void CompositeFilter::SerialCallback() { | 355 void CompositeFilter::SerialCallback() { |
| 335 DCHECK_EQ(message_loop_, MessageLoop::current()); | 356 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 336 if (status_ != PIPELINE_OK) { | 357 if (status_ != PIPELINE_OK) { |
| 337 // We encountered an error. Terminate the sequence now. | 358 // We encountered an error. Terminate the sequence now. |
| 338 ChangeState(kError); | 359 ChangeState(kError); |
| 339 DispatchPendingCallback(status_); | 360 DispatchPendingCallback(status_); |
| 340 return; | 361 return; |
| 341 } | 362 } |
| 342 | |
| 343 if (!filters_.empty()) | 363 if (!filters_.empty()) |
| 344 sequence_index_++; | 364 sequence_index_++; |
| 345 | 365 |
| 346 if (sequence_index_ == filters_.size()) { | 366 if (sequence_index_ == filters_.size()) { |
| 347 // All filters have been successfully called without error. | 367 // All filters have been successfully called without error. |
| 348 OnCallSequenceDone(); | 368 OnCallSequenceDone(); |
| 349 } else if (GetNextState(state_) == kStopPending) { | 369 } else if (GetNextState(state_) == kStopPending) { |
| 350 // Abort sequence early and start issuing Stop() calls. | 370 // Abort sequence early and start issuing Stop() calls. |
| 351 ChangeState(kStopPending); | 371 ChangeState(kStopPending); |
| 352 StartSerialCallSequence(); | 372 StartSerialCallSequence(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 370 DispatchPendingCallback(status_); | 390 DispatchPendingCallback(status_); |
| 371 return; | 391 return; |
| 372 } | 392 } |
| 373 | 393 |
| 374 OnCallSequenceDone(); | 394 OnCallSequenceDone(); |
| 375 } | 395 } |
| 376 } | 396 } |
| 377 | 397 |
| 378 void CompositeFilter::OnCallSequenceDone() { | 398 void CompositeFilter::OnCallSequenceDone() { |
| 379 State next_state = GetNextState(state_); | 399 State next_state = GetNextState(state_); |
| 380 | |
| 381 if (next_state == kInvalid) { | 400 if (next_state == kInvalid) { |
| 382 // We somehow got into an unexpected state. | 401 // We somehow got into an unexpected state. |
| 383 ChangeState(kError); | 402 ChangeState(kError); |
| 384 DispatchPendingCallback(PIPELINE_ERROR_INVALID_STATE); | 403 DispatchPendingCallback(PIPELINE_ERROR_INVALID_STATE); |
| 385 return; | 404 return; |
| 386 } | 405 } |
| 387 | 406 |
| 388 ChangeState(next_state); | 407 ChangeState(next_state); |
| 389 | 408 |
| 390 if (state_ == kStopPending) { | 409 if (state_ == kStopPending) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 557 |
| 539 void CompositeFilter::FilterHostImpl::SetCurrentReadPosition(int64 offset) { | 558 void CompositeFilter::FilterHostImpl::SetCurrentReadPosition(int64 offset) { |
| 540 host_->SetCurrentReadPosition(offset); | 559 host_->SetCurrentReadPosition(offset); |
| 541 } | 560 } |
| 542 | 561 |
| 543 int64 CompositeFilter::FilterHostImpl::GetCurrentReadPosition() { | 562 int64 CompositeFilter::FilterHostImpl::GetCurrentReadPosition() { |
| 544 return host_->GetCurrentReadPosition(); | 563 return host_->GetCurrentReadPosition(); |
| 545 } | 564 } |
| 546 | 565 |
| 547 } // namespace media | 566 } // namespace media |
| OLD | NEW |