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 #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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 } | 50 } |
| 51 | 51 |
| 52 CompositeFilter::~CompositeFilter() { | 52 CompositeFilter::~CompositeFilter() { |
| 53 DCHECK_EQ(message_loop_, MessageLoop::current()); | 53 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 54 DCHECK(state_ == kCreated || state_ == kStopped); | 54 DCHECK(state_ == kCreated || state_ == kStopped); |
| 55 | 55 |
| 56 filters_.clear(); | 56 filters_.clear(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool CompositeFilter::AddFilter(scoped_refptr<Filter> filter) { | 59 bool CompositeFilter::AddFilter(scoped_refptr<Filter> filter) { |
| 60 // TODO(fischman,scherkus): s/bool/void/ the return type and CHECK on failure | |
|
scherkus (not reviewing)
2011/12/09 23:13:55
woah woah woah!
Ami GONE FROM CHROMIUM
2011/12/10 00:03:15
Whaaaaat? You asked for a TODO, you got a TODO.
| |
| 61 // of the sanity-checks that return false today. | |
| 60 DCHECK_EQ(message_loop_, MessageLoop::current()); | 62 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 61 if (!filter.get() || state_ != kCreated || !host()) | 63 if (!filter.get() || state_ != kCreated || !host()) |
| 62 return false; | 64 return false; |
| 63 | 65 |
| 64 // Register ourselves as the filter's host. | 66 // Register ourselves as the filter's host. |
| 65 filter->set_host(host_impl_.get()); | 67 filter->set_host(host_impl_.get()); |
| 66 filters_.push_back(make_scoped_refptr(filter.get())); | 68 filters_.push_back(make_scoped_refptr(filter.get())); |
| 67 return true; | 69 return true; |
| 68 } | 70 } |
| 69 | 71 |
| 72 void CompositeFilter::RemoveFilter(scoped_refptr<Filter> filter) { | |
| 73 DCHECK_EQ(message_loop_, MessageLoop::current()); | |
| 74 if (!filter.get() || state_ != kCreated || !host()) | |
| 75 LOG(FATAL) << "Unknown filter, or in unexpected state."; | |
| 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 CHECK(found); | |
| 87 } | |
| 88 | |
| 70 void CompositeFilter::set_host(FilterHost* host) { | 89 void CompositeFilter::set_host(FilterHost* host) { |
| 71 DCHECK_EQ(message_loop_, MessageLoop::current()); | 90 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 72 DCHECK(host); | 91 DCHECK(host); |
| 73 DCHECK(!host_impl_.get()); | 92 DCHECK(!host_impl_.get()); |
| 74 host_impl_.reset(new FilterHostImpl(this, host)); | 93 host_impl_.reset(new FilterHostImpl(this, host)); |
| 75 } | 94 } |
| 76 | 95 |
| 77 FilterHost* CompositeFilter::host() { | 96 FilterHost* CompositeFilter::host() { |
| 78 return host_impl_.get() ? host_impl_->host() : NULL; | 97 return host_impl_.get() ? host_impl_->host() : NULL; |
| 79 } | 98 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 } | 349 } |
| 331 | 350 |
| 332 void CompositeFilter::SerialCallback() { | 351 void CompositeFilter::SerialCallback() { |
| 333 DCHECK_EQ(message_loop_, MessageLoop::current()); | 352 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 334 if (status_ != PIPELINE_OK) { | 353 if (status_ != PIPELINE_OK) { |
| 335 // We encountered an error. Terminate the sequence now. | 354 // We encountered an error. Terminate the sequence now. |
| 336 ChangeState(kError); | 355 ChangeState(kError); |
| 337 DispatchPendingCallback(status_); | 356 DispatchPendingCallback(status_); |
| 338 return; | 357 return; |
| 339 } | 358 } |
| 340 | |
| 341 if (!filters_.empty()) | 359 if (!filters_.empty()) |
| 342 sequence_index_++; | 360 sequence_index_++; |
| 343 | 361 |
| 344 if (sequence_index_ == filters_.size()) { | 362 if (sequence_index_ == filters_.size()) { |
| 345 // All filters have been successfully called without error. | 363 // All filters have been successfully called without error. |
| 346 OnCallSequenceDone(); | 364 OnCallSequenceDone(); |
| 347 } else if (GetNextState(state_) == kStopPending) { | 365 } else if (GetNextState(state_) == kStopPending) { |
| 348 // Abort sequence early and start issuing Stop() calls. | 366 // Abort sequence early and start issuing Stop() calls. |
| 349 ChangeState(kStopPending); | 367 ChangeState(kStopPending); |
| 350 StartSerialCallSequence(); | 368 StartSerialCallSequence(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 368 DispatchPendingCallback(status_); | 386 DispatchPendingCallback(status_); |
| 369 return; | 387 return; |
| 370 } | 388 } |
| 371 | 389 |
| 372 OnCallSequenceDone(); | 390 OnCallSequenceDone(); |
| 373 } | 391 } |
| 374 } | 392 } |
| 375 | 393 |
| 376 void CompositeFilter::OnCallSequenceDone() { | 394 void CompositeFilter::OnCallSequenceDone() { |
| 377 State next_state = GetNextState(state_); | 395 State next_state = GetNextState(state_); |
| 378 | |
| 379 if (next_state == kInvalid) { | 396 if (next_state == kInvalid) { |
| 380 // We somehow got into an unexpected state. | 397 // We somehow got into an unexpected state. |
| 381 ChangeState(kError); | 398 ChangeState(kError); |
| 382 DispatchPendingCallback(PIPELINE_ERROR_INVALID_STATE); | 399 DispatchPendingCallback(PIPELINE_ERROR_INVALID_STATE); |
| 383 return; | 400 return; |
| 384 } | 401 } |
| 385 | 402 |
| 386 ChangeState(next_state); | 403 ChangeState(next_state); |
| 387 | 404 |
| 388 if (state_ == kStopPending) { | 405 if (state_ == kStopPending) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 | 545 |
| 529 void CompositeFilter::FilterHostImpl::SetCurrentReadPosition(int64 offset) { | 546 void CompositeFilter::FilterHostImpl::SetCurrentReadPosition(int64 offset) { |
| 530 host_->SetCurrentReadPosition(offset); | 547 host_->SetCurrentReadPosition(offset); |
| 531 } | 548 } |
| 532 | 549 |
| 533 int64 CompositeFilter::FilterHostImpl::GetCurrentReadPosition() { | 550 int64 CompositeFilter::FilterHostImpl::GetCurrentReadPosition() { |
| 534 return host_->GetCurrentReadPosition(); | 551 return host_->GetCurrentReadPosition(); |
| 535 } | 552 } |
| 536 | 553 |
| 537 } // namespace media | 554 } // namespace media |
| OLD | NEW |