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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 DCHECK_EQ(message_loop_, MessageLoop::current()); | 60 DCHECK_EQ(message_loop_, MessageLoop::current()); |
61 if (!filter.get() || state_ != kCreated || !host()) | 61 if (!filter.get() || state_ != kCreated || !host()) |
62 return false; | 62 return false; |
scherkus (not reviewing)
2011/12/09 00:26:20
nit: we should TODO / followup CL to make a simila
Ami GONE FROM CHROMIUM
2011/12/09 22:55:50
Done.
| |
63 | 63 |
64 // Register ourselves as the filter's host. | 64 // Register ourselves as the filter's host. |
65 filter->set_host(host_impl_.get()); | 65 filter->set_host(host_impl_.get()); |
66 filters_.push_back(make_scoped_refptr(filter.get())); | 66 filters_.push_back(make_scoped_refptr(filter.get())); |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 void CompositeFilter::RemoveFilter(scoped_refptr<Filter> filter) { | |
71 DCHECK_EQ(message_loop_, MessageLoop::current()); | |
72 if (!filter.get() || state_ != kCreated || !host()) | |
73 LOG(FATAL) << "Unknown filter, or in unexpected state."; | |
74 | |
75 bool found = false; | |
76 for (FilterVector::iterator it = filters_.begin(); | |
77 it != filters_.end() && !found; ++it) { | |
78 if (it->get() == filter.get()) { | |
79 filters_.erase(it); | |
scherkus (not reviewing)
2011/12/09 00:26:20
nit: doesn't filters_.erase(filters_.find(filter))
Ami GONE FROM CHROMIUM
2011/12/09 22:55:50
filters_ is a vector so no find() for you.
Could u
| |
80 found = true; | |
81 } | |
82 } | |
83 filter->clear_host(); | |
84 CHECK(found); | |
85 } | |
86 | |
70 void CompositeFilter::set_host(FilterHost* host) { | 87 void CompositeFilter::set_host(FilterHost* host) { |
71 DCHECK_EQ(message_loop_, MessageLoop::current()); | 88 DCHECK_EQ(message_loop_, MessageLoop::current()); |
72 DCHECK(host); | 89 DCHECK(host); |
73 DCHECK(!host_impl_.get()); | 90 DCHECK(!host_impl_.get()); |
74 host_impl_.reset(new FilterHostImpl(this, host)); | 91 host_impl_.reset(new FilterHostImpl(this, host)); |
75 } | 92 } |
76 | 93 |
77 FilterHost* CompositeFilter::host() { | 94 FilterHost* CompositeFilter::host() { |
78 return host_impl_.get() ? host_impl_->host() : NULL; | 95 return host_impl_.get() ? host_impl_->host() : NULL; |
79 } | 96 } |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 } | 347 } |
331 | 348 |
332 void CompositeFilter::SerialCallback() { | 349 void CompositeFilter::SerialCallback() { |
333 DCHECK_EQ(message_loop_, MessageLoop::current()); | 350 DCHECK_EQ(message_loop_, MessageLoop::current()); |
334 if (status_ != PIPELINE_OK) { | 351 if (status_ != PIPELINE_OK) { |
335 // We encountered an error. Terminate the sequence now. | 352 // We encountered an error. Terminate the sequence now. |
336 ChangeState(kError); | 353 ChangeState(kError); |
337 DispatchPendingCallback(status_); | 354 DispatchPendingCallback(status_); |
338 return; | 355 return; |
339 } | 356 } |
340 | |
341 if (!filters_.empty()) | 357 if (!filters_.empty()) |
342 sequence_index_++; | 358 sequence_index_++; |
343 | 359 |
344 if (sequence_index_ == filters_.size()) { | 360 if (sequence_index_ == filters_.size()) { |
345 // All filters have been successfully called without error. | 361 // All filters have been successfully called without error. |
346 OnCallSequenceDone(); | 362 OnCallSequenceDone(); |
347 } else if (GetNextState(state_) == kStopPending) { | 363 } else if (GetNextState(state_) == kStopPending) { |
348 // Abort sequence early and start issuing Stop() calls. | 364 // Abort sequence early and start issuing Stop() calls. |
349 ChangeState(kStopPending); | 365 ChangeState(kStopPending); |
350 StartSerialCallSequence(); | 366 StartSerialCallSequence(); |
(...skipping 17 matching lines...) Expand all Loading... | |
368 DispatchPendingCallback(status_); | 384 DispatchPendingCallback(status_); |
369 return; | 385 return; |
370 } | 386 } |
371 | 387 |
372 OnCallSequenceDone(); | 388 OnCallSequenceDone(); |
373 } | 389 } |
374 } | 390 } |
375 | 391 |
376 void CompositeFilter::OnCallSequenceDone() { | 392 void CompositeFilter::OnCallSequenceDone() { |
377 State next_state = GetNextState(state_); | 393 State next_state = GetNextState(state_); |
378 | |
379 if (next_state == kInvalid) { | 394 if (next_state == kInvalid) { |
380 // We somehow got into an unexpected state. | 395 // We somehow got into an unexpected state. |
381 ChangeState(kError); | 396 ChangeState(kError); |
382 DispatchPendingCallback(PIPELINE_ERROR_INVALID_STATE); | 397 DispatchPendingCallback(PIPELINE_ERROR_INVALID_STATE); |
383 return; | 398 return; |
384 } | 399 } |
385 | 400 |
386 ChangeState(next_state); | 401 ChangeState(next_state); |
387 | 402 |
388 if (state_ == kStopPending) { | 403 if (state_ == kStopPending) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 | 543 |
529 void CompositeFilter::FilterHostImpl::SetCurrentReadPosition(int64 offset) { | 544 void CompositeFilter::FilterHostImpl::SetCurrentReadPosition(int64 offset) { |
530 host_->SetCurrentReadPosition(offset); | 545 host_->SetCurrentReadPosition(offset); |
531 } | 546 } |
532 | 547 |
533 int64 CompositeFilter::FilterHostImpl::GetCurrentReadPosition() { | 548 int64 CompositeFilter::FilterHostImpl::GetCurrentReadPosition() { |
534 return host_->GetCurrentReadPosition(); | 549 return host_->GetCurrentReadPosition(); |
535 } | 550 } |
536 | 551 |
537 } // namespace media | 552 } // namespace media |
OLD | NEW |