| OLD | NEW |
| 1 // Copyright (c) 2008-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008-2009 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 // TODO(scherkus): clean up PipelineImpl... too many crazy function names, | 5 // TODO(scherkus): clean up PipelineImpl... too many crazy function names, |
| 6 // potential deadlocks, nested message loops, etc... | 6 // potential deadlocks, nested message loops, etc... |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/condition_variable.h" | 9 #include "base/condition_variable.h" |
| 10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
| 11 #include "media/base/filter_host_impl.h" | 11 #include "media/base/filter_host_impl.h" |
| 12 #include "media/base/media_format.h" | 12 #include "media/base/media_format.h" |
| 13 #include "media/base/pipeline_impl.h" | 13 #include "media/base/pipeline_impl.h" |
| 14 | 14 |
| 15 namespace media { | 15 namespace media { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // Small helper function to help us transition over to injected message loops. | 19 // Small helper function to help us transition over to injected message loops. |
| 20 // | 20 // |
| 21 // TODO(scherkus): have every filter support injected message loops. | 21 // TODO(scherkus): have every filter support injected message loops. |
| 22 template <class Filter> | 22 template <class Filter> |
| 23 bool SupportsSetMessageLoop() { | 23 bool SupportsSetMessageLoop() { |
| 24 switch (Filter::filter_type()) { | 24 switch (Filter::filter_type()) { |
| 25 case FILTER_DEMUXER: | 25 case FILTER_DEMUXER: |
| 26 case FILTER_AUDIO_DECODER: |
| 27 case FILTER_VIDEO_DECODER: |
| 26 return true; | 28 return true; |
| 27 default: | 29 default: |
| 28 return false; | 30 return false; |
| 29 } | 31 } |
| 30 } | 32 } |
| 31 | 33 |
| 32 // Helper function used with NewRunnableMethod to implement a (very) crude | 34 // Helper function used with NewRunnableMethod to implement a (very) crude |
| 33 // blocking counter. | 35 // blocking counter. |
| 34 // | 36 // |
| 35 // TODO(scherkus): remove this as soon as Stop() is made asynchronous. | 37 // TODO(scherkus): remove this as soon as Stop() is made asynchronous. |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 init_complete_callback->Run(pipeline_->initialized_); | 451 init_complete_callback->Run(pipeline_->initialized_); |
| 450 delete init_complete_callback; | 452 delete init_complete_callback; |
| 451 } | 453 } |
| 452 } | 454 } |
| 453 | 455 |
| 454 // This method is called as a result of the client calling Pipeline::Stop() or | 456 // This method is called as a result of the client calling Pipeline::Stop() or |
| 455 // as the result of an error condition. If there is no error, then set the | 457 // as the result of an error condition. If there is no error, then set the |
| 456 // pipeline's error_ member to PIPELINE_STOPPING. We stop the filters in the | 458 // pipeline's error_ member to PIPELINE_STOPPING. We stop the filters in the |
| 457 // reverse order. | 459 // reverse order. |
| 458 // | 460 // |
| 459 // TODO(scherkus): beware! this can get posted multiple times! it shouldn't! | 461 // TODO(scherkus): beware! this can get posted multiple times since we post |
| 462 // Stop() tasks even if we've already stopped. Perhaps this should no-op for |
| 463 // additional calls, however most of this logic will be changing. |
| 460 void PipelineThread::StopTask() { | 464 void PipelineThread::StopTask() { |
| 461 if (PipelineOk()) { | 465 if (PipelineOk()) { |
| 462 pipeline_->error_ = PIPELINE_STOPPING; | 466 pipeline_->error_ = PIPELINE_STOPPING; |
| 463 } | 467 } |
| 464 | 468 |
| 465 // Stop every filter. | 469 // Stop every filter. |
| 466 for (FilterHostVector::iterator iter = filter_hosts_.begin(); | 470 for (FilterHostVector::iterator iter = filter_hosts_.begin(); |
| 467 iter != filter_hosts_.end(); | 471 iter != filter_hosts_.end(); |
| 468 ++iter) { | 472 ++iter) { |
| 469 (*iter)->Stop(); | 473 (*iter)->Stop(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 if (!filter) { | 632 if (!filter) { |
| 629 Error(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); | 633 Error(PIPELINE_ERROR_REQUIRED_FILTER_MISSING); |
| 630 } else { | 634 } else { |
| 631 DCHECK(!host_initializing_); | 635 DCHECK(!host_initializing_); |
| 632 host_initializing_ = new FilterHostImpl(this, filter.get()); | 636 host_initializing_ = new FilterHostImpl(this, filter.get()); |
| 633 if (NULL == host_initializing_) { | 637 if (NULL == host_initializing_) { |
| 634 Error(PIPELINE_ERROR_OUT_OF_MEMORY); | 638 Error(PIPELINE_ERROR_OUT_OF_MEMORY); |
| 635 } else { | 639 } else { |
| 636 // Create a dedicated thread for this filter. | 640 // Create a dedicated thread for this filter. |
| 637 if (SupportsSetMessageLoop<Filter>()) { | 641 if (SupportsSetMessageLoop<Filter>()) { |
| 642 // TODO(scherkus): figure out a way to name these threads so it matches |
| 643 // the filter type. |
| 638 scoped_ptr<base::Thread> thread(new base::Thread("FilterThread")); | 644 scoped_ptr<base::Thread> thread(new base::Thread("FilterThread")); |
| 639 if (!thread.get() || !thread->Start()) { | 645 if (!thread.get() || !thread->Start()) { |
| 640 NOTREACHED() << "Could not start filter thread"; | 646 NOTREACHED() << "Could not start filter thread"; |
| 641 Error(PIPELINE_ERROR_INITIALIZATION_FAILED); | 647 Error(PIPELINE_ERROR_INITIALIZATION_FAILED); |
| 642 } else { | 648 } else { |
| 643 filter->SetMessageLoop(thread->message_loop()); | 649 filter->SetMessageLoop(thread->message_loop()); |
| 644 filter_threads_.push_back(thread.release()); | 650 filter_threads_.push_back(thread.release()); |
| 645 } | 651 } |
| 646 } | 652 } |
| 647 | 653 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 | 697 |
| 692 // Called as a result of destruction of the thread. | 698 // Called as a result of destruction of the thread. |
| 693 // | 699 // |
| 694 // TODO(scherkus): this can block the client due to synchronous Stop() API call. | 700 // TODO(scherkus): this can block the client due to synchronous Stop() API call. |
| 695 void PipelineThread::WillDestroyCurrentMessageLoop() { | 701 void PipelineThread::WillDestroyCurrentMessageLoop() { |
| 696 STLDeleteElements(&filter_hosts_); | 702 STLDeleteElements(&filter_hosts_); |
| 697 STLDeleteElements(&filter_threads_); | 703 STLDeleteElements(&filter_threads_); |
| 698 } | 704 } |
| 699 | 705 |
| 700 } // namespace media | 706 } // namespace media |
| OLD | NEW |