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