Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
| 8 #include "media/base/callback.h" | 8 #include "media/base/callback.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 ThreadFactoryFunction thread_factory) { | 48 ThreadFactoryFunction thread_factory) { |
| 49 DCHECK(thread_factory); | 49 DCHECK(thread_factory); |
| 50 Init(message_loop, thread_factory); | 50 Init(message_loop, thread_factory); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void CompositeFilter::Init(MessageLoop* message_loop, | 53 void CompositeFilter::Init(MessageLoop* message_loop, |
| 54 ThreadFactoryFunction thread_factory) { | 54 ThreadFactoryFunction thread_factory) { |
| 55 DCHECK(message_loop); | 55 DCHECK(message_loop); |
| 56 message_loop_ = message_loop; | 56 message_loop_ = message_loop; |
| 57 thread_factory_ = thread_factory; | 57 thread_factory_ = thread_factory; |
| 58 runnable_factory_.reset( | |
| 59 new ScopedRunnableMethodFactory<CompositeFilter>(this)); | |
| 58 | 60 |
| 59 if (!thread_factory_) { | 61 if (!thread_factory_) { |
| 60 thread_factory_ = &CompositeFilter::DefaultThreadFactory; | 62 thread_factory_ = &CompositeFilter::DefaultThreadFactory; |
| 61 } | 63 } |
| 62 | 64 |
| 63 state_ = kCreated; | 65 state_ = kCreated; |
| 64 sequence_index_ = 0; | 66 sequence_index_ = 0; |
| 65 error_ = PIPELINE_OK; | 67 error_ = PIPELINE_OK; |
| 66 } | 68 } |
| 67 | 69 |
| 68 CompositeFilter::~CompositeFilter() { | 70 CompositeFilter::~CompositeFilter() { |
| 69 DCHECK_EQ(message_loop_, MessageLoop::current()); | 71 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 70 DCHECK(state_ == kCreated || state_ == kStopped); | 72 DCHECK(state_ == kCreated || state_ == kStopped); |
| 71 | 73 |
| 72 // Stop every running filter thread. | 74 // Stop every running filter thread. |
| 73 for (FilterThreadVector::iterator iter = filter_threads_.begin(); | 75 for (FilterThreadVector::iterator iter = filter_threads_.begin(); |
| 74 iter != filter_threads_.end(); | 76 iter != filter_threads_.end(); |
| 75 ++iter) { | 77 ++iter) { |
| 76 (*iter)->Stop(); | 78 (*iter)->Stop(); |
| 77 } | 79 } |
| 78 | 80 |
| 79 // Reset the pipeline, which will decrement a reference to this object. | |
| 80 // We will get destroyed as soon as the remaining tasks finish executing. | |
| 81 // To be safe, we'll set our pipeline reference to NULL. | |
|
acolwell GONE FROM CHROMIUM
2011/01/10 22:31:31
Removed because this comment is no longer relevant
| |
| 82 filters_.clear(); | 81 filters_.clear(); |
| 83 STLDeleteElements(&filter_threads_); | 82 STLDeleteElements(&filter_threads_); |
| 84 } | 83 } |
| 85 | 84 |
| 86 bool CompositeFilter::AddFilter(scoped_refptr<Filter> filter) { | 85 bool CompositeFilter::AddFilter(scoped_refptr<Filter> filter) { |
| 87 DCHECK_EQ(message_loop_, MessageLoop::current()); | 86 DCHECK_EQ(message_loop_, MessageLoop::current()); |
| 88 if (!filter.get() || state_ != kCreated || !host()) | 87 if (!filter.get() || state_ != kCreated || !host()) |
| 89 return false; | 88 return false; |
| 90 | 89 |
| 91 // Create a dedicated thread for this filter if applicable. | 90 // Create a dedicated thread for this filter if applicable. |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 if (error != PIPELINE_OK) { | 462 if (error != PIPELINE_OK) { |
| 464 SendErrorToHost(error); | 463 SendErrorToHost(error); |
| 465 } | 464 } |
| 466 | 465 |
| 467 DispatchPendingCallback(); | 466 DispatchPendingCallback(); |
| 468 } | 467 } |
| 469 | 468 |
| 470 FilterCallback* CompositeFilter::NewThreadSafeCallback( | 469 FilterCallback* CompositeFilter::NewThreadSafeCallback( |
| 471 void (CompositeFilter::*method)()) { | 470 void (CompositeFilter::*method)()) { |
| 472 return TaskToCallbackAdapter::NewCallback( | 471 return TaskToCallbackAdapter::NewCallback( |
| 473 NewRunnableMethod(this, | 472 NewRunnableFunction(&CompositeFilter::OnCallback, |
| 474 &CompositeFilter::OnCallback, | 473 message_loop_, |
| 475 message_loop_, | 474 runnable_factory_->NewRunnableMethod(method))); |
| 476 method)); | |
| 477 } | 475 } |
| 478 | 476 |
| 477 // This method is intentionally static so that no reference to the composite | |
| 478 // is needed to call it. This method may be called by other threads and we | |
| 479 // don't want those threads to gain ownership of this composite by having a | |
| 480 // reference to it. |task| will contain a weak reference to the composite | |
| 481 // so that the reference can be cleared if the composite is destroyed before | |
| 482 // the callback is called. | |
| 483 // static | |
| 479 void CompositeFilter::OnCallback(MessageLoop* message_loop, | 484 void CompositeFilter::OnCallback(MessageLoop* message_loop, |
|
scherkus (not reviewing)
2011/01/11 00:36:57
few sanity checks...
Is the issue that someone is
acolwell GONE FROM CHROMIUM
2011/01/11 05:23:59
The issue is that this code was accidentally openi
scherkus (not reviewing)
2011/01/11 18:37:32
Gotcha!
| |
| 480 void (CompositeFilter::*method)()) { | 485 CancelableTask* task) { |
| 481 if (MessageLoop::current() != message_loop) { | 486 if (MessageLoop::current() != message_loop) { |
| 482 // Posting callback to the proper thread. | 487 // Posting callback to the proper thread. |
| 483 message_loop->PostTask(FROM_HERE, NewRunnableMethod(this, method)); | 488 message_loop->PostTask(FROM_HERE, task); |
| 484 return; | 489 return; |
| 485 } | 490 } |
| 486 | 491 |
| 487 (this->*method)(); | 492 task->Run(); |
| 493 delete task; | |
| 488 } | 494 } |
| 489 | 495 |
| 490 bool CompositeFilter::CanForwardError() { | 496 bool CompositeFilter::CanForwardError() { |
| 491 return (state_ == kCreated) || (state_ == kPlaying) || (state_ == kPaused); | 497 return (state_ == kCreated) || (state_ == kPlaying) || (state_ == kPaused); |
| 492 } | 498 } |
| 493 | 499 |
| 494 void CompositeFilter::SetError(PipelineError error) { | 500 void CompositeFilter::SetError(PipelineError error) { |
| 495 // TODO(acolwell): Temporary hack to handle errors that occur | 501 // TODO(acolwell): Temporary hack to handle errors that occur |
| 496 // during filter initialization. In this case we just forward | 502 // during filter initialization. In this case we just forward |
| 497 // the error to the host even if it is on the wrong thread. We | 503 // the error to the host even if it is on the wrong thread. We |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 | 600 |
| 595 void CompositeFilter::FilterHostImpl::SetCurrentReadPosition(int64 offset) { | 601 void CompositeFilter::FilterHostImpl::SetCurrentReadPosition(int64 offset) { |
| 596 host_->SetCurrentReadPosition(offset); | 602 host_->SetCurrentReadPosition(offset); |
| 597 } | 603 } |
| 598 | 604 |
| 599 int64 CompositeFilter::FilterHostImpl::GetCurrentReadPosition() { | 605 int64 CompositeFilter::FilterHostImpl::GetCurrentReadPosition() { |
| 600 return host_->GetCurrentReadPosition(); | 606 return host_->GetCurrentReadPosition(); |
| 601 } | 607 } |
| 602 | 608 |
| 603 } // namespace media | 609 } // namespace media |
| OLD | NEW |