| OLD | NEW |
| 1 // Copyright (c) 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 #include "media/base/filter_host_impl.h" | 5 #include "media/base/filter_host_impl.h" |
| 6 | 6 |
| 7 namespace media { | 7 namespace media { |
| 8 | 8 |
| 9 void FilterHostImpl::SetTimeUpdateCallback( | |
| 10 Callback1<base::TimeDelta>::Type* callback) { | |
| 11 time_update_callback_.reset(callback); | |
| 12 } | |
| 13 | |
| 14 void FilterHostImpl::RunTimeUpdateCallback(base::TimeDelta time) { | |
| 15 if (time_update_callback_.get()) { | |
| 16 time_update_callback_->Run(time); | |
| 17 } | |
| 18 } | |
| 19 | |
| 20 // To understand why this method takes the |caller| parameter, see the comments | |
| 21 // of the TimeUpdatedTask in the file filter_host_impl.h. | |
| 22 void FilterHostImpl::RunScheduledTimeUpdateCallback(TimeUpdateTask* caller) { | |
| 23 time_update_lock_.Acquire(); | |
| 24 if (caller == scheduled_time_update_task_) { | |
| 25 scheduled_time_update_task_ = NULL; | |
| 26 } | |
| 27 time_update_lock_.Release(); | |
| 28 RunTimeUpdateCallback(pipeline()->GetInterpolatedTime()); | |
| 29 } | |
| 30 | |
| 31 void FilterHostImpl::ScheduleTimeUpdateCallback(base::TimeDelta time) { | |
| 32 time_update_lock_.Acquire(); | |
| 33 if (stopped_) { | |
| 34 time_update_lock_.Release(); | |
| 35 } else { | |
| 36 DCHECK(time_update_callback_.get()); | |
| 37 if (scheduled_time_update_task_) { | |
| 38 scheduled_time_update_task_->Cancel(); | |
| 39 } | |
| 40 scheduled_time_update_task_ = new TimeUpdateTask(this); | |
| 41 Task* task = scheduled_time_update_task_; | |
| 42 time_update_lock_.Release(); | |
| 43 | |
| 44 // Here, we compute the delta from now & adjust it by the playback rate. | |
| 45 time -= pipeline()->GetInterpolatedTime(); | |
| 46 int delay = static_cast<int>(time.InMilliseconds()); | |
| 47 float rate = pipeline()->GetPlaybackRate(); | |
| 48 if (rate > 0.0f) { | |
| 49 delay = static_cast<int>(delay / rate); | |
| 50 } | |
| 51 if (delay > 0) { | |
| 52 pipeline_thread_->message_loop()->PostDelayedTask(FROM_HERE, task, delay); | |
| 53 } else { | |
| 54 pipeline_thread_->message_loop()->PostTask(FROM_HERE, task); | |
| 55 } | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 void FilterHostImpl::InitializationComplete() { | 9 void FilterHostImpl::InitializationComplete() { |
| 60 pipeline_thread_->InitializationComplete(this); | 10 pipeline_thread_->InitializationComplete(this); |
| 61 } | 11 } |
| 62 | 12 |
| 63 void FilterHostImpl::Error(PipelineError error) { | 13 void FilterHostImpl::Error(PipelineError error) { |
| 64 pipeline_thread_->Error(error); | 14 pipeline_thread_->Error(error); |
| 65 } | 15 } |
| 66 | 16 |
| 17 base::TimeDelta FilterHostImpl::GetTime() const { |
| 18 return pipeline()->GetTime(); |
| 19 } |
| 20 |
| 67 void FilterHostImpl::SetTime(base::TimeDelta time) { | 21 void FilterHostImpl::SetTime(base::TimeDelta time) { |
| 68 pipeline_thread_->SetTime(time); | 22 pipeline_thread_->SetTime(time); |
| 69 } | 23 } |
| 70 | 24 |
| 71 void FilterHostImpl::SetDuration(base::TimeDelta duration) { | 25 void FilterHostImpl::SetDuration(base::TimeDelta duration) { |
| 72 pipeline()->SetDuration(duration); | 26 pipeline()->SetDuration(duration); |
| 73 } | 27 } |
| 74 | 28 |
| 75 void FilterHostImpl::SetBufferedTime(base::TimeDelta buffered_time) { | 29 void FilterHostImpl::SetBufferedTime(base::TimeDelta buffered_time) { |
| 76 pipeline()->SetBufferedTime(buffered_time); | 30 pipeline()->SetBufferedTime(buffered_time); |
| 77 } | 31 } |
| 78 | 32 |
| 79 void FilterHostImpl::SetTotalBytes(int64 total_bytes) { | 33 void FilterHostImpl::SetTotalBytes(int64 total_bytes) { |
| 80 pipeline()->SetTotalBytes(total_bytes); | 34 pipeline()->SetTotalBytes(total_bytes); |
| 81 } | 35 } |
| 82 | 36 |
| 83 void FilterHostImpl::SetBufferedBytes(int64 buffered_bytes) { | 37 void FilterHostImpl::SetBufferedBytes(int64 buffered_bytes) { |
| 84 pipeline()->SetBufferedBytes(buffered_bytes); | 38 pipeline()->SetBufferedBytes(buffered_bytes); |
| 85 } | 39 } |
| 86 | 40 |
| 87 void FilterHostImpl::SetVideoSize(size_t width, size_t height) { | 41 void FilterHostImpl::SetVideoSize(size_t width, size_t height) { |
| 88 pipeline()->SetVideoSize(width, height); | 42 pipeline()->SetVideoSize(width, height); |
| 89 } | 43 } |
| 90 | 44 |
| 91 const PipelineStatus* FilterHostImpl::GetPipelineStatus() const { | |
| 92 return pipeline(); | |
| 93 } | |
| 94 | |
| 95 void FilterHostImpl::Stop() { | 45 void FilterHostImpl::Stop() { |
| 96 if (!stopped_) { | 46 if (!stopped_) { |
| 97 filter_->Stop(); | 47 filter_->Stop(); |
| 98 AutoLock auto_lock(time_update_lock_); | 48 AutoLock auto_lock(time_update_lock_); |
| 99 stopped_ = true; | 49 stopped_ = true; |
| 100 if (scheduled_time_update_task_) { | |
| 101 scheduled_time_update_task_->Cancel(); | |
| 102 } | |
| 103 } | 50 } |
| 104 } | 51 } |
| 105 | 52 |
| 106 } // namespace media | 53 } // namespace media |
| OLD | NEW |