diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-29 22:36:38 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-29 22:36:38 +0000 |
commit | adabb62712f972e63fb19afc727093b2008d82ad (patch) | |
tree | b384d924ec7531cc9efb7432d290a8b0ab593845 /media | |
parent | 4a338b43f6ecc9e030c9cd177e90f3308ea7fdd4 (diff) | |
download | chromium_src-adabb62712f972e63fb19afc727093b2008d82ad.zip chromium_src-adabb62712f972e63fb19afc727093b2008d82ad.tar.gz chromium_src-adabb62712f972e63fb19afc727093b2008d82ad.tar.bz2 |
Convert all of media/ over to the new base::{Bind,Callback} hotness.
Mostly this was a rote conversion, replacing:
- Pass-by-pointer CallbackN<>'s become pass-by-const-ref Callback<>'s.
- scoped_ptr<CallbackN<>> members become Callback<> members.
- several dedicated FooCallback typedefs became base::Closure.
Because it was only used in a small handful of places and only in one place
profitably, I deleted AutoCallbackRunner.
Because it tickles a Bind bug I disabled mfdecoder in .gyp (about to get deleted in a scherkus CL).
BUG=none
TEST=media_tests, trybots
Review URL: http://codereview.chromium.org/8071007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103376 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
87 files changed, 781 insertions, 1120 deletions
diff --git a/media/audio/audio_input_controller.cc b/media/audio/audio_input_controller.cc index cedbb24..b370612 100644 --- a/media/audio/audio_input_controller.cc +++ b/media/audio/audio_input_controller.cc @@ -4,6 +4,7 @@ #include "media/audio/audio_input_controller.h" +#include "base/bind.h" #include "base/threading/thread_restrictions.h" #include "media/base/limits.h" @@ -50,10 +51,8 @@ scoped_refptr<AudioInputController> AudioInputController::Create( // Start the thread and post a task to create the audio input stream. controller->thread_.Start(); - controller->thread_.message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(controller.get(), &AudioInputController::DoCreate, - params)); + controller->thread_.message_loop()->PostTask(FROM_HERE, base::Bind( + &AudioInputController::DoCreate, controller.get(), params)); return controller; } @@ -76,18 +75,15 @@ scoped_refptr<AudioInputController> AudioInputController::CreateLowLatency( // Start the thread and post a task to create the audio input stream. controller->thread_.Start(); - controller->thread_.message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(controller.get(), &AudioInputController::DoCreate, - params)); + controller->thread_.message_loop()->PostTask(FROM_HERE, base::Bind( + &AudioInputController::DoCreate, controller.get(), params)); return controller; } void AudioInputController::Record() { DCHECK(thread_.IsRunning()); - thread_.message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioInputController::DoRecord)); + thread_.message_loop()->PostTask(FROM_HERE, base::Bind( + &AudioInputController::DoRecord, this)); } void AudioInputController::Close() { @@ -98,9 +94,8 @@ void AudioInputController::Close() { } // Wait for all tasks to complete on the audio thread. - thread_.message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioInputController::DoClose)); + thread_.message_loop()->PostTask(FROM_HERE, base::Bind( + &AudioInputController::DoClose, this)); // A ScopedAllowIO object is required to join the thread when calling Stop. // This is because as joining threads may be a long operation it's now @@ -130,9 +125,8 @@ void AudioInputController::DoCreate(const AudioParameters& params) { return; } - thread_.message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioInputController::DoResetNoDataTimer)); + thread_.message_loop()->PostTask(FROM_HERE, base::Bind( + &AudioInputController::DoResetNoDataTimer, this)); state_ = kCreated; handler_->OnCreated(this); } @@ -196,9 +190,8 @@ void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, return; } - thread_.message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioInputController::DoResetNoDataTimer)); + thread_.message_loop()->PostTask(FROM_HERE, base::Bind( + &AudioInputController::DoResetNoDataTimer, this)); // Use SyncSocket if we are in a low-latency mode. if (LowLatencyMode()) { @@ -218,9 +211,8 @@ void AudioInputController::OnClose(AudioInputStream* stream) { void AudioInputController::OnError(AudioInputStream* stream, int code) { // Handle error on the audio controller thread. - thread_.message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioInputController::DoReportError, code)); + thread_.message_loop()->PostTask(FROM_HERE, base::Bind( + &AudioInputController::DoReportError, this, code)); } } // namespace media diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index 8acbe66..b8536f9 100644 --- a/media/audio/audio_output_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -4,6 +4,7 @@ #include "media/audio/audio_output_controller.h" +#include "base/bind.h" #include "base/debug/trace_event.h" #include "base/message_loop.h" @@ -47,10 +48,8 @@ scoped_refptr<AudioOutputController> AudioOutputController::Create( controller->message_loop_ = AudioManager::GetAudioManager()->GetMessageLoop(); - controller->message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(controller.get(), &AudioOutputController::DoCreate, - params)); + controller->message_loop_->PostTask(FROM_HERE, base::Bind( + &AudioOutputController::DoCreate, controller.get(), params)); return controller; } @@ -74,47 +73,40 @@ scoped_refptr<AudioOutputController> AudioOutputController::CreateLowLatency( controller->message_loop_ = AudioManager::GetAudioManager()->GetMessageLoop(); - controller->message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(controller.get(), &AudioOutputController::DoCreate, - params)); + controller->message_loop_->PostTask(FROM_HERE, base::Bind( + &AudioOutputController::DoCreate, controller.get(), params)); return controller; } void AudioOutputController::Play() { DCHECK(message_loop_); - message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioOutputController::DoPlay)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &AudioOutputController::DoPlay, this)); } void AudioOutputController::Pause() { DCHECK(message_loop_); - message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioOutputController::DoPause)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &AudioOutputController::DoPause, this)); } void AudioOutputController::Flush() { DCHECK(message_loop_); - message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioOutputController::DoFlush)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &AudioOutputController::DoFlush, this)); } -void AudioOutputController::Close(Task* closed_task) { - DCHECK(closed_task); +void AudioOutputController::Close(const base::Closure& closed_task) { + DCHECK(!closed_task.is_null()); DCHECK(message_loop_); - message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioOutputController::DoClose, closed_task)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &AudioOutputController::DoClose, this, closed_task)); } void AudioOutputController::SetVolume(double volume) { DCHECK(message_loop_); - message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioOutputController::DoSetVolume, volume)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &AudioOutputController::DoSetVolume, this, volume)); } void AudioOutputController::EnqueueData(const uint8* data, uint32 size) { @@ -223,7 +215,7 @@ void AudioOutputController::DoFlush() { } } -void AudioOutputController::DoClose(Task* closed_task) { +void AudioOutputController::DoClose(const base::Closure& closed_task) { DCHECK_EQ(message_loop_, MessageLoop::current()); if (state_ != kClosed) { @@ -243,8 +235,7 @@ void AudioOutputController::DoClose(Task* closed_task) { state_ = kClosed; } - closed_task->Run(); - delete closed_task; + closed_task.Run(); } void AudioOutputController::DoSetVolume(double volume) { @@ -297,9 +288,8 @@ uint32 AudioOutputController::OnMoreData( void AudioOutputController::OnError(AudioOutputStream* stream, int code) { // Handle error on the audio controller thread. - message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, &AudioOutputController::DoReportError, code)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &AudioOutputController::DoReportError, this, code)); } void AudioOutputController::SubmitOnMoreData_Locked() { diff --git a/media/audio/audio_output_controller.h b/media/audio/audio_output_controller.h index ac4fea7..528f0d2 100644 --- a/media/audio/audio_output_controller.h +++ b/media/audio/audio_output_controller.h @@ -5,6 +5,7 @@ #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ #define MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ +#include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" @@ -15,7 +16,6 @@ #include "media/audio/simple_sources.h" class MessageLoop; -class Task; // An AudioOutputController controls an AudioOutputStream and provides data // to this output stream. It has an important function that it executes @@ -142,7 +142,7 @@ class MEDIA_EXPORT AudioOutputController // // It is safe to call this method more than once. Calls after the first one // will have no effect. - void Close(Task* closed_task); + void Close(const base::Closure& closed_task); // Sets the volume of the audio output stream. void SetVolume(double volume); @@ -169,7 +169,7 @@ class MEDIA_EXPORT AudioOutputController void DoPlay(); void DoPause(); void DoFlush(); - void DoClose(Task* closed_task); + void DoClose(const base::Closure& closed_task); void DoSetVolume(double volume); void DoReportError(int code); diff --git a/media/audio/audio_output_controller_unittest.cc b/media/audio/audio_output_controller_unittest.cc index 0f94ae5..cab9929 100644 --- a/media/audio/audio_output_controller_unittest.cc +++ b/media/audio/audio_output_controller_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" #include "base/environment.h" #include "base/basictypes.h" #include "base/logging.h" @@ -83,7 +84,7 @@ static void SignalClosedEvent(base::WaitableEvent* event) { // Closes AudioOutputController synchronously. static void CloseAudioController(AudioOutputController* controller) { base::WaitableEvent closed_event(true, false); - controller->Close(NewRunnableFunction(&SignalClosedEvent, &closed_event)); + controller->Close(base::Bind(&SignalClosedEvent, &closed_event)); closed_event.Wait(); } @@ -320,10 +321,10 @@ TEST(AudioOutputControllerTest, CloseTwice) { event.Wait(); base::WaitableEvent closed_event_1(true, false); - controller->Close(NewRunnableFunction(&SignalClosedEvent, &closed_event_1)); + controller->Close(base::Bind(&SignalClosedEvent, &closed_event_1)); base::WaitableEvent closed_event_2(true, false); - controller->Close(NewRunnableFunction(&SignalClosedEvent, &closed_event_2)); + controller->Close(base::Bind(&SignalClosedEvent, &closed_event_2)); closed_event_1.Wait(); closed_event_2.Wait(); diff --git a/media/audio/audio_output_dispatcher.cc b/media/audio/audio_output_dispatcher.cc index ac08bcb..7deae9d 100644 --- a/media/audio/audio_output_dispatcher.cc +++ b/media/audio/audio_output_dispatcher.cc @@ -4,6 +4,7 @@ #include "media/audio/audio_output_dispatcher.h" +#include "base/bind.h" #include "base/compiler_specific.h" #include "base/message_loop.h" #include "base/time.h" @@ -56,8 +57,8 @@ AudioOutputStream* AudioOutputDispatcher::StreamStarted() { close_timer_.Reset(); // Schedule task to allocate streams for other proxies if we need to. - message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &AudioOutputDispatcher::OpenTask)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &AudioOutputDispatcher::OpenTask, this)); return stream; } @@ -73,7 +74,7 @@ void AudioOutputDispatcher::StreamStopped(AudioOutputStream* stream) { // Don't recycle stream until two buffers worth of time has elapsed. message_loop_->PostDelayedTask( FROM_HERE, - NewRunnableMethod(this, &AudioOutputDispatcher::StopStreamTask), + base::Bind(&AudioOutputDispatcher::StopStreamTask, this), pause_delay_milliseconds_); } diff --git a/media/audio/fake_audio_input_stream.cc b/media/audio/fake_audio_input_stream.cc index 26ac880..b84db92 100644 --- a/media/audio/fake_audio_input_stream.cc +++ b/media/audio/fake_audio_input_stream.cc @@ -1,9 +1,11 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "media/audio/fake_audio_input_stream.h" +#include "base/bind.h" + using base::Time; using base::TimeDelta; @@ -40,7 +42,7 @@ void FakeAudioInputStream::Start(AudioInputCallback* callback) { thread_.Start(); thread_.message_loop()->PostDelayedTask( FROM_HERE, - NewRunnableMethod(this, &FakeAudioInputStream::DoCallback), + base::Bind(&FakeAudioInputStream::DoCallback, this), callback_interval_ms_); } @@ -60,7 +62,7 @@ void FakeAudioInputStream::DoCallback() { last_callback_time_ = now; thread_.message_loop()->PostDelayedTask( FROM_HERE, - NewRunnableMethod(this, &FakeAudioInputStream::DoCallback), + base::Bind(&FakeAudioInputStream::DoCallback, this), next_callback_ms); } diff --git a/media/audio/linux/alsa_input.cc b/media/audio/linux/alsa_input.cc index 1eba936..9864fb9 100644 --- a/media/audio/linux/alsa_input.cc +++ b/media/audio/linux/alsa_input.cc @@ -5,6 +5,7 @@ #include "media/audio/linux/alsa_input.h" #include "base/basictypes.h" +#include "base/bind.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/time.h" @@ -34,7 +35,7 @@ AlsaPcmInputStream::AlsaPcmInputStream(const std::string& device_name, params.sample_rate), callback_(NULL), device_handle_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), read_callback_behind_schedule_(false) { } @@ -102,7 +103,7 @@ void AlsaPcmInputStream::Start(AudioInputCallback* callback) { delay_ms); MessageLoop::current()->PostDelayedTask( FROM_HERE, - task_factory_.NewRunnableMethod(&AlsaPcmInputStream::ReadAudio), + base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), delay_ms); } } @@ -152,7 +153,7 @@ void AlsaPcmInputStream::ReadAudio() { } MessageLoop::current()->PostDelayedTask( FROM_HERE, - task_factory_.NewRunnableMethod(&AlsaPcmInputStream::ReadAudio), + base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), kNoAudioReadAgainTimeoutMs); return; } @@ -185,7 +186,7 @@ void AlsaPcmInputStream::ReadAudio() { MessageLoop::current()->PostDelayedTask( FROM_HERE, - task_factory_.NewRunnableMethod(&AlsaPcmInputStream::ReadAudio), + base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), delay_ms); } @@ -193,7 +194,7 @@ void AlsaPcmInputStream::Stop() { if (!device_handle_ || !callback_) return; - task_factory_.RevokeAll(); // Cancel the next scheduled read. + weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. int error = wrapper_->PcmDrop(device_handle_); if (error < 0) HandleError("PcmDrop", error); @@ -206,7 +207,7 @@ void AlsaPcmInputStream::Close() { if (!device_handle_ || !callback_) return; - task_factory_.RevokeAll(); // Cancel the next scheduled read. + weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read. int error = alsa_util::CloseDevice(wrapper_, device_handle_); if (error < 0) HandleError("PcmClose", error); diff --git a/media/audio/linux/alsa_input.h b/media/audio/linux/alsa_input.h index 33b2c8a..e97737f 100644 --- a/media/audio/linux/alsa_input.h +++ b/media/audio/linux/alsa_input.h @@ -10,7 +10,7 @@ #include <string> #include "base/memory/scoped_ptr.h" -#include "base/task.h" +#include "base/memory/weak_ptr.h" #include "media/audio/audio_io.h" #include "media/audio/audio_parameters.h" @@ -58,7 +58,7 @@ class AlsaPcmInputStream : public AudioInputStream { AudioInputCallback* callback_; // Valid during a recording session. base::Time next_read_time_; // Scheduled time for the next read callback. snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device. - ScopedRunnableMethodFactory<AlsaPcmInputStream> task_factory_; + base::WeakPtrFactory<AlsaPcmInputStream> weak_factory_; scoped_array<uint8> audio_packet_; // Buffer used for reading audio data. bool read_callback_behind_schedule_; diff --git a/media/audio/linux/alsa_output.cc b/media/audio/linux/alsa_output.cc index 3c3ec8d..91b1efd 100644 --- a/media/audio/linux/alsa_output.cc +++ b/media/audio/linux/alsa_output.cc @@ -41,6 +41,7 @@ #include <algorithm> +#include "base/bind.h" #include "base/debug/trace_event.h" #include "base/logging.h" #include "base/message_loop.h" @@ -203,7 +204,7 @@ AlsaPcmOutputStream::AlsaPcmOutputStream(const std::string& device_name, playback_handle_(NULL), frames_per_packet_(packet_size_ / bytes_per_frame_), message_loop_(message_loop), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), state_(kCreated), volume_(1.0f), source_callback_(NULL) { @@ -258,7 +259,7 @@ bool AlsaPcmOutputStream::Open() { TransitionTo(kIsOpened); message_loop_->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod(&AlsaPcmOutputStream::OpenTask)); + base::Bind(&AlsaPcmOutputStream::OpenTask, weak_factory_.GetWeakPtr())); return true; } @@ -274,7 +275,7 @@ void AlsaPcmOutputStream::Close() { message_loop_->PostTask( FROM_HERE, - method_factory_.NewRunnableMethod(&AlsaPcmOutputStream::CloseTask)); + base::Bind(&AlsaPcmOutputStream::CloseTask, weak_factory_.GetWeakPtr())); } void AlsaPcmOutputStream::Start(AudioSourceCallback* callback) { @@ -286,9 +287,8 @@ void AlsaPcmOutputStream::Start(AudioSourceCallback* callback) { // Only post the task if we can enter the playing state. if (TransitionTo(kIsPlaying) == kIsPlaying) { - message_loop_->PostTask( - FROM_HERE, - method_factory_.NewRunnableMethod(&AlsaPcmOutputStream::StartTask)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &AlsaPcmOutputStream::StartTask, weak_factory_.GetWeakPtr())); } } @@ -408,7 +408,7 @@ void AlsaPcmOutputStream::CloseTask() { // Signal anything that might already be scheduled to stop. stop_stream_ = true; // Not necessary in production, but unit tests // uses the flag to verify that stream was closed. - method_factory_.RevokeAll(); + weak_factory_.InvalidateWeakPtrs(); // Signal to the manager that we're closed and can be removed. // Should be last call in the method as it deletes "this". @@ -626,15 +626,14 @@ void AlsaPcmOutputStream::ScheduleNextWrite(bool source_exhausted) { // Only schedule more reads/writes if we are still in the playing state. if (state() == kIsPlaying) { if (next_fill_time_ms == 0) { - message_loop_->PostTask( - FROM_HERE, - method_factory_.NewRunnableMethod(&AlsaPcmOutputStream::WriteTask)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &AlsaPcmOutputStream::WriteTask, weak_factory_.GetWeakPtr())); } else { // TODO(ajwong): Measure the reliability of the delay interval. Use // base/metrics/histogram.h. message_loop_->PostDelayedTask( - FROM_HERE, - method_factory_.NewRunnableMethod(&AlsaPcmOutputStream::WriteTask), + FROM_HERE, base::Bind( + &AlsaPcmOutputStream::WriteTask, weak_factory_.GetWeakPtr()), next_fill_time_ms); } } diff --git a/media/audio/linux/alsa_output.h b/media/audio/linux/alsa_output.h index 8d61148..bf85d75 100644 --- a/media/audio/linux/alsa_output.h +++ b/media/audio/linux/alsa_output.h @@ -34,7 +34,7 @@ #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" -#include "base/task.h" +#include "base/memory/weak_ptr.h" #include "media/audio/audio_io.h" #include "media/audio/audio_parameters.h" @@ -209,7 +209,7 @@ class MEDIA_EXPORT AlsaPcmOutputStream : public AudioOutputStream { // Allows us to run tasks on the AlsaPcmOutputStream instance which are // bound by its lifetime. - ScopedRunnableMethodFactory<AlsaPcmOutputStream> method_factory_; + base::WeakPtrFactory<AlsaPcmOutputStream> weak_factory_; InternalState state_; float volume_; // Volume level from 0.0 to 1.0. diff --git a/media/audio/linux/pulse_output.cc b/media/audio/linux/pulse_output.cc index fe5e694..009aad6 100644 --- a/media/audio/linux/pulse_output.cc +++ b/media/audio/linux/pulse_output.cc @@ -144,7 +144,7 @@ PulseAudioOutputStream::PulseAudioOutputStream(const AudioParameters& params, stream_stopped_(true), write_callback_handled_(false), message_loop_(message_loop), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), source_callback_(NULL) { DCHECK_EQ(message_loop_, MessageLoop::current()); DCHECK(manager_); @@ -284,10 +284,9 @@ void PulseAudioOutputStream::WaitForWriteRequest() { write_callback_handled_ = false; pa_mainloop_iterate(pa_mainloop_, 1, NULL); if (!write_callback_handled_) { - message_loop_->PostTask( - FROM_HERE, - method_factory_.NewRunnableMethod( - &PulseAudioOutputStream::WaitForWriteRequest)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &PulseAudioOutputStream::WaitForWriteRequest, + weak_factory_.GetWeakPtr())); } } @@ -345,17 +344,15 @@ void PulseAudioOutputStream::FulfillWriteRequest(size_t requested_bytes) { if (bytes_written < requested_bytes) { // We weren't able to buffer enough data to fulfill the request. Try to // fulfill the rest of the request later. - message_loop_->PostTask( - FROM_HERE, - method_factory_.NewRunnableMethod( - &PulseAudioOutputStream::FulfillWriteRequest, - requested_bytes - bytes_written)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &PulseAudioOutputStream::FulfillWriteRequest, + weak_factory_.GetWeakPtr(), + requested_bytes - bytes_written)); } else { // Continue playback. - message_loop_->PostTask( - FROM_HERE, - method_factory_.NewRunnableMethod( - &PulseAudioOutputStream::WaitForWriteRequest)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &PulseAudioOutputStream::WaitForWriteRequest, + weak_factory_.GetWeakPtr())); } } @@ -389,10 +386,9 @@ void PulseAudioOutputStream::Start(AudioSourceCallback* callback) { stream_stopped_ = false; // Start playback. - message_loop_->PostTask( - FROM_HERE, - method_factory_.NewRunnableMethod( - &PulseAudioOutputStream::WaitForWriteRequest)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &PulseAudioOutputStream::WaitForWriteRequest, + weak_factory_.GetWeakPtr())); } void PulseAudioOutputStream::Stop() { diff --git a/media/audio/linux/pulse_output.h b/media/audio/linux/pulse_output.h index 7da9228..46aab57 100644 --- a/media/audio/linux/pulse_output.h +++ b/media/audio/linux/pulse_output.h @@ -22,6 +22,7 @@ #include <pulse/pulseaudio.h> #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "base/task.h" #include "media/audio/audio_io.h" #include "media/base/channel_layout.h" @@ -119,7 +120,7 @@ class PulseAudioOutputStream : public AudioOutputStream { // Allows us to run tasks on the PulseAudioOutputStream instance which are // bound by its lifetime. - ScopedRunnableMethodFactory<PulseAudioOutputStream> method_factory_; + base::WeakPtrFactory<PulseAudioOutputStream> weak_factory_; // Callback to audio data source. AudioSourceCallback* source_callback_; diff --git a/media/base/async_filter_factory_base.cc b/media/base/async_filter_factory_base.cc index c8bb307..b37f619 100644 --- a/media/base/async_filter_factory_base.cc +++ b/media/base/async_filter_factory_base.cc @@ -4,6 +4,7 @@ #include "media/base/async_filter_factory_base.h" +#include "base/bind.h" #include "base/logging.h" #include "base/stl_util.h" @@ -17,44 +18,43 @@ AsyncDataSourceFactoryBase::~AsyncDataSourceFactoryBase() { } void AsyncDataSourceFactoryBase::Build(const std::string& url, - BuildCallback* callback) { - DCHECK(callback); + const BuildCallback& callback) { + DCHECK(!callback.is_null()); BuildRequest* request = NULL; { base::AutoLock auto_lock(lock_); if (url.empty()) { - RunAndDestroyCallback(PIPELINE_ERROR_URL_NOT_FOUND, callback); + ReportError(PIPELINE_ERROR_URL_NOT_FOUND, callback); return; } if (!AllowRequests()) { - RunAndDestroyCallback(DATASOURCE_ERROR_URL_NOT_SUPPORTED, callback); + ReportError(DATASOURCE_ERROR_URL_NOT_SUPPORTED, callback); return; } request = CreateRequest(url, callback); if (!request) { - RunAndDestroyCallback(DATASOURCE_ERROR_URL_NOT_SUPPORTED, callback); + ReportError(DATASOURCE_ERROR_URL_NOT_SUPPORTED, callback); return; } outstanding_requests_.insert(request); } - request->Start(NewCallback(this, - &AsyncDataSourceFactoryBase::BuildRequestDone)); + request->Start(base::Bind( + &AsyncDataSourceFactoryBase::BuildRequestDone, base::Unretained(this))); } -void AsyncDataSourceFactoryBase::RunAndDestroyCallback( +void AsyncDataSourceFactoryBase::ReportError( PipelineStatus error, - BuildCallback* callback) const { + const BuildCallback& callback) const { DCHECK_NE(error, PIPELINE_OK); - DCHECK(callback); + DCHECK(!callback.is_null()); - callback->Run(error, static_cast<DataSource*>(NULL)); - delete callback; + callback.Run(error, static_cast<DataSource*>(NULL)); } void AsyncDataSourceFactoryBase::BuildRequestDone(BuildRequest* request) { @@ -63,8 +63,8 @@ void AsyncDataSourceFactoryBase::BuildRequestDone(BuildRequest* request) { delete request; } -AsyncDataSourceFactoryBase::BuildRequest::BuildRequest(const std::string& url, - BuildCallback* callback) +AsyncDataSourceFactoryBase::BuildRequest::BuildRequest( + const std::string& url, const BuildCallback& callback) : url_(url), callback_(callback) { } @@ -72,11 +72,11 @@ AsyncDataSourceFactoryBase::BuildRequest::BuildRequest(const std::string& url, AsyncDataSourceFactoryBase::BuildRequest::~BuildRequest() {} void AsyncDataSourceFactoryBase::BuildRequest::Start( - RequestDoneCallback* done_callback) { - DCHECK(done_callback); - DCHECK(!done_callback_.get()); + const RequestDoneCallback& done_callback) { + DCHECK(!done_callback.is_null()); + DCHECK(done_callback_.is_null()); - done_callback_.reset(done_callback); + done_callback_ = done_callback; DoStart(); // Don't do anything after this line since the object could // have been deleted at this point if the request was completed @@ -86,13 +86,15 @@ void AsyncDataSourceFactoryBase::BuildRequest::Start( void AsyncDataSourceFactoryBase::BuildRequest::RequestComplete( PipelineStatus status, DataSource* data_source) { - DCHECK(callback_.get()); - DCHECK(done_callback_.get()); + DCHECK(!callback_.is_null()); + DCHECK(!done_callback_.is_null()); // Transfer ownership to local variables just in case the // request object gets deleted by one of the callbacks. - scoped_ptr<RequestDoneCallback> done_callback(done_callback_.release()); - scoped_ptr<BuildCallback> callback(callback_.release()); + RequestDoneCallback done_callback; + std::swap(done_callback, done_callback_); + BuildCallback callback; + std::swap(callback, callback_); // Notify factory that this request has completed. We do this before // calling |callback| so the factory doesn't consider this request @@ -100,9 +102,9 @@ void AsyncDataSourceFactoryBase::BuildRequest::RequestComplete( // // NOTE: This BuildRequest object is destroyed inside this callback so // no modifications should be made to this object after this call. - done_callback->Run(this); + done_callback.Run(this); - callback->Run(status, data_source); + callback.Run(status, data_source); } const std::string& AsyncDataSourceFactoryBase::BuildRequest::url() const { diff --git a/media/base/async_filter_factory_base.h b/media/base/async_filter_factory_base.h index c4a76a2..0f512d1 100644 --- a/media/base/async_filter_factory_base.h +++ b/media/base/async_filter_factory_base.h @@ -54,7 +54,7 @@ class MEDIA_EXPORT AsyncDataSourceFactoryBase : public DataSourceFactory { // DataSourceFactory method. // Derived classes should not overload this Build() method. AllowRequests() & // CreateRequest() should be implemented instead. - virtual void Build(const std::string& url, BuildCallback* callback); + virtual void Build(const std::string& url, const BuildCallback& callback); // DataSourceFactory method. // Clone() must be implemented by derived classes. @@ -66,12 +66,12 @@ class MEDIA_EXPORT AsyncDataSourceFactoryBase : public DataSourceFactory { protected: class MEDIA_EXPORT BuildRequest { public: - BuildRequest(const std::string& url, BuildCallback* callback); + BuildRequest(const std::string& url, const BuildCallback& callback); virtual ~BuildRequest(); - typedef Callback1<BuildRequest*>::Type RequestDoneCallback; + typedef base::Callback<void(BuildRequest*)> RequestDoneCallback; // Starts the build request. - void Start(RequestDoneCallback* done_callback); + void Start(const RequestDoneCallback& done_callback); // Derived objects call this method to indicate that the build request // has completed. If the build was successful |status| should be set to @@ -95,8 +95,8 @@ class MEDIA_EXPORT AsyncDataSourceFactoryBase : public DataSourceFactory { private: std::string url_; - scoped_ptr<BuildCallback> callback_; - scoped_ptr<RequestDoneCallback> done_callback_; + BuildCallback callback_; + RequestDoneCallback done_callback_; DISALLOW_COPY_AND_ASSIGN(BuildRequest); }; @@ -108,13 +108,11 @@ class MEDIA_EXPORT AsyncDataSourceFactoryBase : public DataSourceFactory { // Implemented by derived class. Called by Build() to allow derived objects // to create their own custom BuildRequest implementations. virtual BuildRequest* CreateRequest(const std::string& url, - BuildCallback* callback) = 0; + const BuildCallback& callback) = 0; private: - void RunAndDestroyCallback(PipelineStatus status, - BuildCallback* callback) const; + void ReportError(PipelineStatus error, const BuildCallback& callback) const; - typedef Callback1<BuildRequest*>::Type RequestDoneCallback; void BuildRequestDone(BuildRequest* request); base::Lock lock_; diff --git a/media/base/callback.cc b/media/base/callback.cc deleted file mode 100644 index fea4e01..0000000 --- a/media/base/callback.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "media/base/callback.h" - -namespace media { - -AutoCallbackRunner::~AutoCallbackRunner() { - if (callback_.get()) { - callback_->Run(); - } -} - -Callback0::Type* TaskToCallbackAdapter::NewCallback(Task* task) { - return new TaskToCallbackAdapter(task); -} - -TaskToCallbackAdapter::~TaskToCallbackAdapter() {} - -void TaskToCallbackAdapter::RunWithParams(const Tuple0& params) { - task_->Run(); -} - -TaskToCallbackAdapter::TaskToCallbackAdapter(Task* task) : task_(task) {} - - -// Helper class used to implement NewCallbackForClosure(). It simply -// holds onto the Closure until Run() is called. When Run() is called, -// the closure is run and this object deletes itself. -// -// TODO(acolwell): Delete this once all old style callbacks have been -// removed from the media code. -class RunClosureAndDeleteHelper { - public: - explicit RunClosureAndDeleteHelper(const base::Closure& cb) - : cb_(cb) { - DCHECK(!cb_.is_null()); - } - - void Run() { - cb_.Run(); - delete this; - } - - private: - ~RunClosureAndDeleteHelper() {} - - base::Closure cb_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(RunClosureAndDeleteHelper); -}; - -// TODO(acolwell): Delete this once all old style callbacks have been -// removed from the media code. -Callback0::Type* NewCallbackForClosure(const base::Closure& cb) { - return NewCallback(new RunClosureAndDeleteHelper(cb), - &RunClosureAndDeleteHelper::Run); -} - -} // namespace media diff --git a/media/base/callback.h b/media/base/callback.h deleted file mode 100644 index 78bc661..0000000 --- a/media/base/callback.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Some basic utilities for aiding in the management of Tasks and Callbacks. -// -// AutoCallbackRunner is akin to scoped_ptr for callbacks. It is useful for -// ensuring a callback is executed and delete in the face of multiple return -// points in a function. -// -// TaskToCallbackAdapter converts a Task to a Callback0::Type since the two type -// hierarchies are strangely separate. -// -// CleanupCallback wraps another Callback and provides the ability to register -// objects for deletion as well as cleanup tasks that will be run on the -// callback's destruction. The deletion and cleanup tasks will be run on -// whatever thread the CleanupCallback is destroyed in. - -#ifndef MEDIA_BASE_CALLBACK_ -#define MEDIA_BASE_CALLBACK_ - -#include <vector> - -#include "base/callback.h" -#include "base/callback_old.h" -#include "base/memory/scoped_ptr.h" -#include "base/task.h" -#include "media/base/media_export.h" - -namespace media { - -class MEDIA_EXPORT AutoCallbackRunner { - public: - // Takes ownership of the callback. - explicit AutoCallbackRunner(Callback0::Type* callback) - : callback_(callback) { - } - - ~AutoCallbackRunner(); - - Callback0::Type* release() { return callback_.release(); } - - private: - scoped_ptr<Callback0::Type> callback_; - - DISALLOW_COPY_AND_ASSIGN(AutoCallbackRunner); -}; - -class TaskToCallbackAdapter : public Callback0::Type { - public: - static Callback0::Type* NewCallback(Task* task); - - virtual ~TaskToCallbackAdapter(); - - virtual void RunWithParams(const Tuple0& params); - - private: - TaskToCallbackAdapter(Task* task); - - scoped_ptr<Task> task_; - - DISALLOW_COPY_AND_ASSIGN(TaskToCallbackAdapter); -}; - -// TODO(acolwell): Delete this once all old style callbacks have been -// removed from the media code. -// -// The new callback stores a copy of |cb| so the lifetime of the copy -// matches the lifetime of the new callback. -Callback0::Type* NewCallbackForClosure(const base::Closure& cb); - -} // namespace media - -#endif // MEDIA_BASE_CALLBACK_ diff --git a/media/base/composite_data_source_factory.cc b/media/base/composite_data_source_factory.cc index 9703c85..e751505 100644 --- a/media/base/composite_data_source_factory.cc +++ b/media/base/composite_data_source_factory.cc @@ -4,7 +4,7 @@ #include "media/base/composite_data_source_factory.h" -#include "base/callback.h" +#include "base/bind.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/stl_util.h" @@ -14,7 +14,7 @@ namespace media { class CompositeDataSourceFactory::BuildRequest : public AsyncDataSourceFactoryBase::BuildRequest { public: - BuildRequest(const std::string& url, BuildCallback* callback, + BuildRequest(const std::string& url, const BuildCallback& callback, const FactoryList& factories); ~BuildRequest(); @@ -58,13 +58,13 @@ bool CompositeDataSourceFactory::AllowRequests() const { AsyncDataSourceFactoryBase::BuildRequest* CompositeDataSourceFactory::CreateRequest(const std::string& url, - BuildCallback* callback) { + const BuildCallback& callback) { return new BuildRequest(url, callback, factories_); } CompositeDataSourceFactory::BuildRequest::BuildRequest( const std::string& url, - BuildCallback* callback, + const BuildCallback& callback, const FactoryList& factories) : AsyncDataSourceFactoryBase::BuildRequest(url, callback), factories_(factories){ @@ -83,7 +83,8 @@ void CompositeDataSourceFactory::BuildRequest::CallNextFactory() { DataSourceFactory* factory = factories_.front(); factories_.pop_front(); - factory->Build(url(), NewCallback(this, &BuildRequest::OnBuildDone)); + factory->Build(url(), base::Bind(&BuildRequest::OnBuildDone, + base::Unretained(this))); } void CompositeDataSourceFactory::BuildRequest::OnBuildDone( diff --git a/media/base/composite_data_source_factory.h b/media/base/composite_data_source_factory.h index d2ead5b..c714bbe 100644 --- a/media/base/composite_data_source_factory.h +++ b/media/base/composite_data_source_factory.h @@ -29,7 +29,7 @@ class MEDIA_EXPORT CompositeDataSourceFactory // AsyncDataSourceFactoryBase methods. virtual bool AllowRequests() const; virtual AsyncDataSourceFactoryBase::BuildRequest* CreateRequest( - const std::string& url, BuildCallback* callback); + const std::string& url, const BuildCallback& callback); private: class BuildRequest; diff --git a/media/base/composite_filter.cc b/media/base/composite_filter.cc index d58bfec..a7af090 100644 --- a/media/base/composite_filter.cc +++ b/media/base/composite_filter.cc @@ -5,9 +5,9 @@ #include "media/base/composite_filter.h" #include "base/bind.h" +#include "base/callback.h" #include "base/message_loop.h" #include "base/stl_util.h" -#include "media/base/callback.h" namespace media { @@ -46,10 +46,9 @@ CompositeFilter::CompositeFilter(MessageLoop* message_loop) : state_(kCreated), sequence_index_(0), message_loop_(message_loop), - status_(PIPELINE_OK) { + status_(PIPELINE_OK), + weak_ptr_factory_(this) { DCHECK(message_loop); - runnable_factory_.reset( - new ScopedRunnableMethodFactory<CompositeFilter>(this)); } CompositeFilter::~CompositeFilter() { @@ -81,75 +80,71 @@ FilterHost* CompositeFilter::host() { return host_impl_.get() ? host_impl_->host() : NULL; } -void CompositeFilter::Play(FilterCallback* play_callback) { +void CompositeFilter::Play(const base::Closure& play_callback) { DCHECK_EQ(message_loop_, MessageLoop::current()); - scoped_ptr<FilterCallback> callback(play_callback); if (IsOperationPending()) { SendErrorToHost(PIPELINE_ERROR_OPERATION_PENDING); - callback->Run(); + play_callback.Run(); return; } else if (state_ == kPlaying) { - callback->Run(); + play_callback.Run(); return; } else if (!host() || (state_ != kPaused && state_ != kCreated)) { SendErrorToHost(PIPELINE_ERROR_INVALID_STATE); - callback->Run(); + play_callback.Run(); return; } ChangeState(kPlayPending); - callback_.reset(callback.release()); + callback_ = play_callback; StartSerialCallSequence(); } -void CompositeFilter::Pause(FilterCallback* pause_callback) { +void CompositeFilter::Pause(const base::Closure& pause_callback) { DCHECK_EQ(message_loop_, MessageLoop::current()); - scoped_ptr<FilterCallback> callback(pause_callback); if (IsOperationPending()) { SendErrorToHost(PIPELINE_ERROR_OPERATION_PENDING); - callback->Run(); + pause_callback.Run(); return; } else if (state_ == kPaused) { - callback->Run(); + pause_callback.Run(); return; } else if (!host() || state_ != kPlaying) { SendErrorToHost(PIPELINE_ERROR_INVALID_STATE); - callback->Run(); + pause_callback.Run(); return; } ChangeState(kPausePending); - callback_.reset(callback.release()); + callback_ = pause_callback; StartSerialCallSequence(); } -void CompositeFilter::Flush(FilterCallback* flush_callback) { +void CompositeFilter::Flush(const base::Closure& flush_callback) { DCHECK_EQ(message_loop_, MessageLoop::current()); - scoped_ptr<FilterCallback> callback(flush_callback); if (IsOperationPending()) { SendErrorToHost(PIPELINE_ERROR_OPERATION_PENDING); - callback->Run(); + flush_callback.Run(); return; } else if (!host() || (state_ != kCreated && state_ != kPaused)) { SendErrorToHost(PIPELINE_ERROR_INVALID_STATE); - callback->Run(); + flush_callback.Run(); return; } ChangeState(kFlushPending); - callback_.reset(callback.release()); + callback_ = flush_callback; StartParallelCallSequence(); } -void CompositeFilter::Stop(FilterCallback* stop_callback) { +void CompositeFilter::Stop(const base::Closure& stop_callback) { DCHECK_EQ(message_loop_, MessageLoop::current()); - scoped_ptr<FilterCallback> callback(stop_callback); if (!host()) { SendErrorToHost(PIPELINE_ERROR_INVALID_STATE); - callback->Run(); + stop_callback.Run(); return; } else if (state_ == kStopped) { - callback->Run(); + stop_callback.Run(); return; } @@ -174,11 +169,11 @@ void CompositeFilter::Stop(FilterCallback* stop_callback) { break; default: SendErrorToHost(PIPELINE_ERROR_INVALID_STATE); - callback->Run(); + stop_callback.Run(); return; } - callback_.reset(callback.release()); + callback_ = stop_callback; if (state_ == kStopPending) { StartSerialCallSequence(); } @@ -254,7 +249,7 @@ void CompositeFilter::StartParallelCallSequence() { } void CompositeFilter::CallFilter(scoped_refptr<Filter>& filter, - FilterCallback* callback) { + const base::Closure& callback) { switch (state_) { case kPlayPending: filter->Play(callback); @@ -273,27 +268,24 @@ void CompositeFilter::CallFilter(scoped_refptr<Filter>& filter, base::Bind(&CompositeFilter::OnStatusCB, this, callback)); break; default: - delete callback; + ChangeState(kError); DispatchPendingCallback(PIPELINE_ERROR_INVALID_STATE); } } void CompositeFilter::DispatchPendingCallback(PipelineStatus status) { - DCHECK((status_cb_.is_null() && callback_.get()) || - (!status_cb_.is_null() && !callback_.get())); + DCHECK(status_cb_.is_null() ^ callback_.is_null()); if (!status_cb_.is_null()) { ResetAndRunCB(&status_cb_, status); return; } - if (callback_.get()) { + if (!callback_.is_null()) { if (status != PIPELINE_OK) SendErrorToHost(status); - - scoped_ptr<FilterCallback> callback(callback_.release()); - callback->Run(); + ResetAndRunCB(&callback_); } } @@ -405,31 +397,29 @@ void CompositeFilter::SendErrorToHost(PipelineStatus error) { host_impl_.get()->host()->SetError(error); } -FilterCallback* CompositeFilter::NewThreadSafeCallback( +base::Closure CompositeFilter::NewThreadSafeCallback( void (CompositeFilter::*method)()) { - return TaskToCallbackAdapter::NewCallback( - NewRunnableFunction(&CompositeFilter::OnCallback, - message_loop_, - runnable_factory_->NewRunnableMethod(method))); + return base::Bind(&CompositeFilter::OnCallback, + message_loop_, + base::Bind(method, weak_ptr_factory_.GetWeakPtr())); } // This method is intentionally static so that no reference to the composite // is needed to call it. This method may be called by other threads and we // don't want those threads to gain ownership of this composite by having a -// reference to it. |task| will contain a weak reference to the composite +// reference to it. |closure| will contain a weak reference to the composite // so that the reference can be cleared if the composite is destroyed before // the callback is called. // static void CompositeFilter::OnCallback(MessageLoop* message_loop, - CancelableTask* task) { + const base::Closure& closure) { if (MessageLoop::current() != message_loop) { // Posting callback to the proper thread. - message_loop->PostTask(FROM_HERE, task); + message_loop->PostTask(FROM_HERE, closure); return; } - task->Run(); - delete task; + closure.Run(); } bool CompositeFilter::CanForwardError() { @@ -437,18 +427,18 @@ bool CompositeFilter::CanForwardError() { } bool CompositeFilter::IsOperationPending() const { - DCHECK(!(callback_.get() && !status_cb_.is_null())); + DCHECK(callback_.is_null() || status_cb_.is_null()); - return callback_.get() || !status_cb_.is_null(); + return !callback_.is_null() || !status_cb_.is_null(); } -void CompositeFilter::OnStatusCB(FilterCallback* callback, +void CompositeFilter::OnStatusCB(const base::Closure& callback, PipelineStatus status) { if (status != PIPELINE_OK) SetError(status); - callback->Run(); - delete callback; + callback.Run(); + } void CompositeFilter::SetError(PipelineStatus error) { @@ -465,7 +455,7 @@ void CompositeFilter::SetError(PipelineStatus error) { if (message_loop_ != MessageLoop::current()) { message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &CompositeFilter::SetError, error)); + base::Bind(&CompositeFilter::SetError, this, error)); return; } diff --git a/media/base/composite_filter.h b/media/base/composite_filter.h index ad070bc..712fecb 100644 --- a/media/base/composite_filter.h +++ b/media/base/composite_filter.h @@ -7,7 +7,8 @@ #include <vector> -#include "base/task.h" +#include "base/callback.h" +#include "base/memory/weak_ptr.h" #include "media/base/filter_host.h" #include "media/base/filters.h" @@ -29,10 +30,10 @@ class MEDIA_EXPORT CompositeFilter : public Filter { // media::Filter methods. virtual void set_host(FilterHost* host) OVERRIDE; virtual FilterHost* host() OVERRIDE; - virtual void Play(FilterCallback* play_callback) OVERRIDE; - virtual void Pause(FilterCallback* pause_callback) OVERRIDE; - virtual void Flush(FilterCallback* flush_callback) OVERRIDE; - virtual void Stop(FilterCallback* stop_callback) OVERRIDE; + virtual void Play(const base::Closure& play_callback) OVERRIDE; + virtual void Pause(const base::Closure& pause_callback) OVERRIDE; + virtual void Flush(const base::Closure& flush_callback) OVERRIDE; + virtual void Stop(const base::Closure& stop_callback) OVERRIDE; virtual void SetPlaybackRate(float playback_rate) OVERRIDE; virtual void Seek( base::TimeDelta time, const FilterStatusCB& seek_cb) OVERRIDE; @@ -74,7 +75,7 @@ class MEDIA_EXPORT CompositeFilter : public Filter { void StartParallelCallSequence(); // Call the filter based on the current value of state_. - void CallFilter(scoped_refptr<Filter>& filter, FilterCallback* callback); + void CallFilter(scoped_refptr<Filter>& filter, const base::Closure& callback); // Calls |callback_| and then clears the reference. void DispatchPendingCallback(PipelineStatus status); @@ -96,12 +97,12 @@ class MEDIA_EXPORT CompositeFilter : public Filter { // Creates a callback that can be called from any thread, but is guaranteed // to call the specified method on the thread associated with this filter. - FilterCallback* NewThreadSafeCallback(void (CompositeFilter::*method)()); + base::Closure NewThreadSafeCallback(void (CompositeFilter::*method)()); // Helper function used by NewThreadSafeCallback() to make sure the // method gets called on the right thread. static void OnCallback(MessageLoop* message_loop, - CancelableTask* task); + const base::Closure& closure); // Helper function that indicates whether SetError() calls can be forwarded // to the host of this filter. @@ -111,18 +112,17 @@ class MEDIA_EXPORT CompositeFilter : public Filter { // pending. bool IsOperationPending() const; - // Called by operations that take a FilterStatusCB instead of a - // FilterCallback. - // TODO: Remove when FilterCallback goes away. - void OnStatusCB(FilterCallback* callback, PipelineStatus status); + // Called by operations that take a FilterStatusCB instead of a Closure. + // TODO: Remove when Closures are replaced by FilterStatusCB. + void OnStatusCB(const base::Closure& callback, PipelineStatus status); // Vector of the filters added to the composite. typedef std::vector<scoped_refptr<Filter> > FilterVector; FilterVector filters_; // Callback for the pending request. - // TODO: Remove callback_ when FilterCallback is removed. - scoped_ptr<FilterCallback> callback_; + // TODO: Remove callback_ when Closures are replaced by FilterStatusCB. + base::Closure callback_; FilterStatusCB status_cb_; // Time parameter for the pending Seek() request. @@ -144,7 +144,7 @@ class MEDIA_EXPORT CompositeFilter : public Filter { // PIPELINE_OK, or last error passed to SetError(). PipelineStatus status_; - scoped_ptr<ScopedRunnableMethodFactory<CompositeFilter> > runnable_factory_; + base::WeakPtrFactory<CompositeFilter> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(CompositeFilter); }; diff --git a/media/base/composite_filter_unittest.cc b/media/base/composite_filter_unittest.cc index bb43af0..52b80db 100644 --- a/media/base/composite_filter_unittest.cc +++ b/media/base/composite_filter_unittest.cc @@ -55,13 +55,13 @@ class CompositeFilterTest : public testing::Test { // equals SEEK. // |callback| - The callback object to pass to the method. // |expected_status| - Some filter methods use a FilterStatusCB instead of - // a FilterCallback. For these methods this function + // a Closure. For these methods this function // creates a FilterStatusCB that makes sure the status // passed to the callback matches |expected_status| and // then calls |callback|. void DoFilterCall(MethodToCall method_to_call, Filter* filter, base::TimeDelta seek_time, - FilterCallback* callback, + const base::Closure& callback, PipelineStatus expected_status); // Creates an expectation sequence based on the value of method_to_call. @@ -112,7 +112,7 @@ class CompositeFilterTest : public testing::Test { // Callback passed to |filter_1_| during last Play(), Pause(), Flush(), // or Stop() call. - FilterCallback* filter_1_callback_; + base::Closure filter_1_callback_; // Status to pass to |filter_1_status_cb_|. PipelineStatus filter_1_status_; @@ -125,7 +125,7 @@ class CompositeFilterTest : public testing::Test { // Callback passed to |filter_2_| during last Play(), Pause(), Flush(), // Stop(), or Seek() call. - FilterCallback* filter_2_callback_; + base::Closure filter_2_callback_; // Status to pass to |filter_2_status_cb_|. PipelineStatus filter_2_status_; @@ -141,9 +141,7 @@ class CompositeFilterTest : public testing::Test { CompositeFilterTest::CompositeFilterTest() : composite_(new CompositeFilter(&message_loop_)), - filter_1_callback_(NULL), filter_1_status_(PIPELINE_OK), - filter_2_callback_(NULL), filter_2_status_(PIPELINE_OK), mock_filter_host_(new StrictMock<MockFilterHost>()) { } @@ -158,7 +156,7 @@ void CompositeFilterTest::SetupAndAdd2Filters() { // Setup |filter_1_| and arrange for methods to set // |filter_1_callback_| when they are called. filter_1_ = new StrictMock<MockFilter>(); - filter_1_callback_ = NULL; + filter_1_callback_.Reset(); filter_1_status_ = PIPELINE_OK; filter_1_status_cb_.Reset(); ON_CALL(*filter_1_, Play(_)) @@ -175,7 +173,7 @@ void CompositeFilterTest::SetupAndAdd2Filters() { // Setup |filter_2_| and arrange for methods to set // |filter_2_callback_| when they are called. filter_2_ = new StrictMock<MockFilter>(); - filter_2_callback_ = NULL; + filter_2_callback_.Reset(); filter_2_status_ = PIPELINE_OK; filter_2_status_cb_.Reset(); ON_CALL(*filter_2_, Play(_)) @@ -215,18 +213,16 @@ void CompositeFilterTest::ExpectFilterCall(MethodToCall method_to_call, }; } -void OnStatusCB(PipelineStatus expected_status, FilterCallback* callback, +void OnStatusCB(PipelineStatus expected_status, const base::Closure& callback, PipelineStatus status) { EXPECT_EQ(status, expected_status); - - callback->Run(); - delete callback; + callback.Run(); } void CompositeFilterTest::DoFilterCall(MethodToCall method_to_call, Filter* filter, base::TimeDelta seek_time, - FilterCallback* callback, + const base::Closure& callback, PipelineStatus expected_status) { filter_1_status_ = expected_status; filter_2_status_ = expected_status; @@ -265,7 +261,8 @@ void CompositeFilterTest::ExpectSuccess(MethodToCall method_to_call, // Make method call on the composite. StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); - DoFilterCall(method_to_call, composite_.get(), seek_time, callback, + DoFilterCall(method_to_call, composite_.get(), seek_time, + base::Bind(&MockCallback::Run, callback), PIPELINE_OK); if (is_parallel_call) { @@ -287,7 +284,7 @@ void CompositeFilterTest::ExpectSuccess(MethodToCall method_to_call, EXPECT_TRUE(HasFilter2Callback()); } - callback->ExpectRunAndDelete(); + EXPECT_CALL(*callback, Run()); RunFilter2Callback(); } @@ -331,8 +328,8 @@ void CompositeFilterTest::ExpectInvalidStateFail(MethodToCall method_to_call, } bool CompositeFilterTest::HasFilter1Callback() const { - CHECK(!(filter_1_callback_ && !filter_1_status_cb_.is_null())); - return filter_1_callback_ != NULL || !filter_1_status_cb_.is_null(); + CHECK(filter_1_callback_.is_null() || filter_1_status_cb_.is_null()); + return !filter_1_callback_.is_null() || !filter_1_status_cb_.is_null(); } void CompositeFilterTest::RunFilter1Callback() { @@ -344,16 +341,15 @@ void CompositeFilterTest::RunFilter1Callback() { return; } - EXPECT_TRUE(filter_1_callback_ != NULL); - FilterCallback* callback = filter_1_callback_; - filter_1_callback_ = NULL; - callback->Run(); - delete callback; + EXPECT_TRUE(!filter_1_callback_.is_null()); + base::Closure callback = filter_1_callback_; + filter_1_callback_.Reset(); + callback.Run(); } bool CompositeFilterTest::HasFilter2Callback() const { - CHECK(!(filter_2_callback_ && !filter_2_status_cb_.is_null())); - return filter_2_callback_ != NULL || !filter_2_status_cb_.is_null(); + CHECK(filter_2_callback_.is_null() || filter_2_status_cb_.is_null()); + return !filter_2_callback_.is_null() || !filter_2_status_cb_.is_null(); } void CompositeFilterTest::RunFilter2Callback() { @@ -365,11 +361,10 @@ void CompositeFilterTest::RunFilter2Callback() { return; } - EXPECT_TRUE(filter_2_callback_ != NULL); - FilterCallback* callback = filter_2_callback_; - filter_2_callback_ = NULL; - callback->Run(); - delete callback; + EXPECT_FALSE(filter_2_callback_.is_null()); + base::Closure callback = filter_2_callback_; + filter_2_callback_.Reset(); + callback.Run(); } // Test AddFilter() failure cases. @@ -442,7 +437,7 @@ TEST_F(CompositeFilterTest, TestPlayErrors) { // Call Play() on the composite. StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); - composite_->Play(callback); + composite_->Play(base::Bind(&MockCallback::Run, callback)); EXPECT_CALL(*filter_2_, Play(_)); @@ -455,7 +450,7 @@ TEST_F(CompositeFilterTest, TestPlayErrors) { // Expect error to be reported and "play done" callback to be called. EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); - callback->ExpectRunAndDelete(); + EXPECT_CALL(*callback, Run()); // Run callback to indicate that |filter_2_|'s Play() has completed. RunFilter2Callback(); @@ -521,7 +516,7 @@ TEST_F(CompositeFilterTest, TestPauseErrors) { // Call Pause() on the composite. StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); - composite_->Pause(callback); + composite_->Pause(base::Bind(&MockCallback::Run, callback)); // Simulate an error by calling SetError() on |filter_1_|'s FilterHost // interface. @@ -529,7 +524,7 @@ TEST_F(CompositeFilterTest, TestPauseErrors) { // Expect error to be reported and "pause done" callback to be called. EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); - callback->ExpectRunAndDelete(); + EXPECT_CALL(*callback, Run()); RunFilter1Callback(); @@ -588,7 +583,7 @@ TEST_F(CompositeFilterTest, TestFlushErrors) { // Call Flush() on the composite. StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); - composite_->Flush(callback); + composite_->Flush(base::Bind(&MockCallback::Run, callback)); // Simulate an error by calling SetError() on |filter_1_|'s FilterHost // interface. @@ -598,7 +593,7 @@ TEST_F(CompositeFilterTest, TestFlushErrors) { // Expect error to be reported and "pause done" callback to be called. EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY)); - callback->ExpectRunAndDelete(); + EXPECT_CALL(*callback, Run()); RunFilter2Callback(); @@ -655,7 +650,7 @@ TEST_F(CompositeFilterTest, TestStop) { EXPECT_CALL(*filter_1_, Stop(_)); StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); - composite_->Stop(callback); + composite_->Stop(base::Bind(&MockCallback::Run, callback)); // Have |filter_1_| signal an error. filter_1_->host()->SetError(PIPELINE_ERROR_READ); @@ -664,7 +659,7 @@ TEST_F(CompositeFilterTest, TestStop) { RunFilter1Callback(); - callback->ExpectRunAndDelete(); + EXPECT_CALL(*callback, Run()); RunFilter2Callback(); } @@ -678,14 +673,12 @@ TEST_F(CompositeFilterTest, TestStopWhilePlayPending) { EXPECT_CALL(*filter_1_, Play(_)); StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); - composite_->Play(callback); + composite_->Play(base::Bind(&MockCallback::Run, callback)); // Note: Play() is pending on |filter_1_| right now. - EXPECT_CALL(*callback, Destructor()); - callback = new StrictMock<MockCallback>(); - composite_->Stop(callback); + composite_->Stop(base::Bind(&MockCallback::Run, callback)); EXPECT_CALL(*filter_1_, Stop(_)); @@ -697,7 +690,7 @@ TEST_F(CompositeFilterTest, TestStopWhilePlayPending) { // Run |filter_1_|'s callback again to indicate Stop() has completed. RunFilter1Callback(); - callback->ExpectRunAndDelete(); + EXPECT_CALL(*callback, Run()); // Run |filter_2_|'s callback to indicate Stop() has completed. RunFilter2Callback(); @@ -713,14 +706,12 @@ TEST_F(CompositeFilterTest, TestStopWhileFlushPending) { EXPECT_CALL(*filter_2_, Flush(_)); StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); - composite_->Flush(callback); + composite_->Flush(base::Bind(&MockCallback::Run, callback)); // Note: |filter_1_| and |filter_2_| have pending Flush() calls at this point. - EXPECT_CALL(*callback, Destructor()); - callback = new StrictMock<MockCallback>(); - composite_->Stop(callback); + composite_->Stop(base::Bind(&MockCallback::Run, callback)); // Run callback to indicate that |filter_1_|'s Flush() has completed. RunFilter1Callback(); @@ -735,7 +726,7 @@ TEST_F(CompositeFilterTest, TestStopWhileFlushPending) { // Run callback to indicate that |filter_1_|'s Stop() has completed. RunFilter1Callback(); - callback->ExpectRunAndDelete(); + EXPECT_CALL(*callback, Run()); // Run callback to indicate that |filter_2_|'s Stop() has completed. RunFilter2Callback(); diff --git a/media/base/demuxer.cc b/media/base/demuxer.cc index f84260c..83bfce3 100644 --- a/media/base/demuxer.cc +++ b/media/base/demuxer.cc @@ -25,11 +25,9 @@ void Demuxer::Seek(base::TimeDelta time, const PipelineStatusCB& callback) { callback.Run(PIPELINE_OK); } -void Demuxer::Stop(FilterCallback* callback) { - DCHECK(callback); - - callback->Run(); - delete callback; +void Demuxer::Stop(const base::Closure& callback) { + DCHECK(!callback.is_null()); + callback.Run(); } void Demuxer::OnAudioRendererDisabled() {} diff --git a/media/base/demuxer.h b/media/base/demuxer.h index 5bdb446..d6013ff 100644 --- a/media/base/demuxer.h +++ b/media/base/demuxer.h @@ -39,9 +39,7 @@ class MEDIA_EXPORT Demuxer // The pipeline is being stopped either as a result of an error or because // the client called Stop(). - // - // TODO(acolwell): Convert to base::Closure. - virtual void Stop(FilterCallback* callback); + virtual void Stop(const base::Closure& callback); // This method is called from the pipeline when the audio renderer // is disabled. Demuxers can ignore the notification if they do not diff --git a/media/base/filter_factories.h b/media/base/filter_factories.h index 4e34c0f..8b27c11 100644 --- a/media/base/filter_factories.h +++ b/media/base/filter_factories.h @@ -7,7 +7,7 @@ #include<string> -#include "base/callback_old.h" +#include "base/callback.h" #include "media/base/media_export.h" #include "media/base/pipeline_status.h" @@ -19,12 +19,12 @@ class DataSource; class MEDIA_EXPORT DataSourceFactory { public: // Ownership of the DataSource is transferred through this callback. - typedef Callback2<PipelineStatus, DataSource*>::Type BuildCallback; + typedef base::Callback<void(PipelineStatus, DataSource*)> BuildCallback; virtual ~DataSourceFactory(); // Builds a DataSource for |url| and returns it via |callback|. - virtual void Build(const std::string& url, BuildCallback* callback) = 0; + virtual void Build(const std::string& url, const BuildCallback& callback) = 0; // Makes a copy of this factory. // NOTE: Pending requests are not cloned. @@ -37,12 +37,12 @@ class Demuxer; class MEDIA_EXPORT DemuxerFactory { public: // Ownership of the Demuxer is transferred through this callback. - typedef Callback2<PipelineStatus, Demuxer*>::Type BuildCallback; + typedef base::Callback<void(PipelineStatus, Demuxer*)> BuildCallback; virtual ~DemuxerFactory(); // Builds a Demuxer for |url| and returns it via |callback|. - virtual void Build(const std::string& url, BuildCallback* callback) = 0; + virtual void Build(const std::string& url, const BuildCallback& callback) = 0; // Makes a copy of this factory. // NOTE: Pending requests are not cloned. diff --git a/media/base/filters.cc b/media/base/filters.cc index bc105de..877f391 100644 --- a/media/base/filters.cc +++ b/media/base/filters.cc @@ -8,13 +8,23 @@ namespace media { +// static +const size_t DataSource::kReadError = static_cast<size_t>(-1); + void ResetAndRunCB(FilterStatusCB* cb, PipelineStatus status) { - DCHECK(cb); + DCHECK(!cb->is_null()); FilterStatusCB tmp_cb(*cb); cb->Reset(); tmp_cb.Run(status); } +void ResetAndRunCB(base::Closure* cb) { + DCHECK(!cb->is_null()); + base::Closure tmp_cb(*cb); + cb->Reset(); + tmp_cb.Run(); +} + Filter::Filter() : host_(NULL) {} Filter::~Filter() {} @@ -29,28 +39,24 @@ FilterHost* Filter::host() { return host_; } -void Filter::Play(FilterCallback* callback) { - DCHECK(callback); - callback->Run(); - delete callback; +void Filter::Play(const base::Closure& callback) { + DCHECK(!callback.is_null()); + callback.Run(); } -void Filter::Pause(FilterCallback* callback) { - DCHECK(callback); - callback->Run(); - delete callback; +void Filter::Pause(const base::Closure& callback) { + DCHECK(!callback.is_null()); + callback.Run(); } -void Filter::Flush(FilterCallback* callback) { - DCHECK(callback); - callback->Run(); - delete callback; +void Filter::Flush(const base::Closure& callback) { + DCHECK(!callback.is_null()); + callback.Run(); } -void Filter::Stop(FilterCallback* callback) { - DCHECK(callback); - callback->Run(); - delete callback; +void Filter::Stop(const base::Closure& callback) { + DCHECK(!callback.is_null()); + callback.Run(); } void Filter::SetPlaybackRate(float playback_rate) {} diff --git a/media/base/filters.h b/media/base/filters.h index c11c943..8873bfc 100644 --- a/media/base/filters.h +++ b/media/base/filters.h @@ -27,7 +27,6 @@ #include <string> #include "base/callback.h" -#include "base/callback_old.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/time.h" @@ -61,16 +60,16 @@ enum Preload { }; // Used for completing asynchronous methods. -typedef Callback0::Type FilterCallback; typedef base::Callback<void(PipelineStatus)> FilterStatusCB; -// This function copies |cb|, calls Reset() on |cb|, and then calls Run() +// This function copies |*cb|, calls Reset() on |*cb|, and then calls Run() // on the copy. This is used in the common case where you need to clear // a callback member variable before running the callback. MEDIA_EXPORT void ResetAndRunCB(FilterStatusCB* cb, PipelineStatus status); +MEDIA_EXPORT void ResetAndRunCB(base::Closure* cb); // Used for updating pipeline statistics. -typedef Callback1<const PipelineStatistics&>::Type StatisticsCallback; +typedef base::Callback<void(const PipelineStatistics&)> StatisticsCallback; class MEDIA_EXPORT Filter : public base::RefCountedThreadSafe<Filter> { public: @@ -87,22 +86,22 @@ class MEDIA_EXPORT Filter : public base::RefCountedThreadSafe<Filter> { // The pipeline has resumed playback. Filters can continue requesting reads. // Filters may implement this method if they need to respond to this call. // TODO(boliu): Check that callback is not NULL in subclasses. - virtual void Play(FilterCallback* callback); + virtual void Play(const base::Closure& callback); // The pipeline has paused playback. Filters should stop buffer exchange. // Filters may implement this method if they need to respond to this call. // TODO(boliu): Check that callback is not NULL in subclasses. - virtual void Pause(FilterCallback* callback); + virtual void Pause(const base::Closure& callback); // The pipeline has been flushed. Filters should return buffer to owners. // Filters may implement this method if they need to respond to this call. // TODO(boliu): Check that callback is not NULL in subclasses. - virtual void Flush(FilterCallback* callback); + virtual void Flush(const base::Closure& callback); // The pipeline is being stopped either as a result of an error or because // the client called Stop(). // TODO(boliu): Check that callback is not NULL in subclasses. - virtual void Stop(FilterCallback* callback); + virtual void Stop(const base::Closure& callback); // The pipeline playback rate has been changed. Filters may implement this // method if they need to respond to this call. @@ -132,8 +131,8 @@ class MEDIA_EXPORT Filter : public base::RefCountedThreadSafe<Filter> { class MEDIA_EXPORT DataSource : public Filter { public: - typedef Callback1<size_t>::Type ReadCallback; - static const size_t kReadError = static_cast<size_t>(-1); + typedef base::Callback<void(size_t)> ReadCallback; + static const size_t kReadError; // Reads |size| bytes from |position| into |data|. And when the read is done // or failed, |read_callback| is called with the number of bytes read or @@ -141,7 +140,8 @@ class MEDIA_EXPORT DataSource : public Filter { // TODO(hclam): should change |size| to int! It makes the code so messy // with size_t and int all over the place.. virtual void Read(int64 position, size_t size, - uint8* data, ReadCallback* read_callback) = 0; + uint8* data, + const DataSource::ReadCallback& read_callback) = 0; // Returns true and the file size, false if the file size could not be // retrieved. @@ -164,8 +164,8 @@ class MEDIA_EXPORT VideoDecoder : public Filter { // Initialize a VideoDecoder with the given DemuxerStream, executing the // callback upon completion. // stats_callback is used to update global pipeline statistics. - virtual void Initialize(DemuxerStream* stream, FilterCallback* callback, - StatisticsCallback* stats_callback) = 0; + virtual void Initialize(DemuxerStream* stream, const base::Closure& callback, + const StatisticsCallback& stats_callback) = 0; // Renderer provides an output buffer for Decoder to write to. These buffers // will be recycled to renderer via the permanent callback. @@ -212,8 +212,8 @@ class MEDIA_EXPORT AudioDecoder : public Filter { // Initialize a AudioDecoder with the given DemuxerStream, executing the // callback upon completion. // stats_callback is used to update global pipeline statistics. - virtual void Initialize(DemuxerStream* stream, FilterCallback* callback, - StatisticsCallback* stats_callback) = 0; + virtual void Initialize(DemuxerStream* stream, const base::Closure& callback, + const StatisticsCallback& stats_callback) = 0; // Renderer provides an output buffer for Decoder to write to. These buffers // will be recycled to renderer via the permanent callback. @@ -249,8 +249,8 @@ class MEDIA_EXPORT VideoRenderer : public Filter { public: // Initialize a VideoRenderer with the given VideoDecoder, executing the // callback upon completion. - virtual void Initialize(VideoDecoder* decoder, FilterCallback* callback, - StatisticsCallback* stats_callback) = 0; + virtual void Initialize(VideoDecoder* decoder, const base::Closure& callback, + const StatisticsCallback& stats_callback) = 0; // Returns true if this filter has received and processed an end-of-stream // buffer. @@ -262,7 +262,8 @@ class MEDIA_EXPORT AudioRenderer : public Filter { public: // Initialize a AudioRenderer with the given AudioDecoder, executing the // callback upon completion. - virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback) = 0; + virtual void Initialize(AudioDecoder* decoder, + const base::Closure& callback) = 0; // Returns true if this filter has received and processed an end-of-stream // buffer. diff --git a/media/base/media_log.cc b/media/base/media_log.cc index af205dd..dead5bd 100644 --- a/media/base/media_log.cc +++ b/media/base/media_log.cc @@ -7,6 +7,7 @@ #include <string> #include "base/atomic_sequence_num.h" +#include "base/bind.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/values.h" @@ -239,8 +240,9 @@ void MediaLog::QueueStatisticsUpdatedEvent(PipelineStatistics stats) { // so we simply leave stats updating for another call to trigger. if (!stats_update_pending_ && MessageLoop::current()) { stats_update_pending_ = true; - MessageLoop::current()->PostDelayedTask(FROM_HERE, - NewRunnableMethod(this, &media::MediaLog::AddStatisticsUpdatedEvent), + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&media::MediaLog::AddStatisticsUpdatedEvent, this), 500); } } diff --git a/media/base/mock_callback.cc b/media/base/mock_callback.cc index cc4f141..fe991f8 100644 --- a/media/base/mock_callback.cc +++ b/media/base/mock_callback.cc @@ -12,54 +12,19 @@ using ::testing::StrictMock; namespace media { MockCallback::MockCallback() {} +MockCallback::~MockCallback() {} -MockCallback::~MockCallback() { - Destructor(); -} - -void MockCallback::ExpectRunAndDelete() { - EXPECT_CALL(*this, RunWithParams(_)); - EXPECT_CALL(*this, Destructor()); -} - -MockStatusCallback::MockStatusCallback() {} - -MockStatusCallback::~MockStatusCallback() { - Destructor(); -} - -// Required by GMock to allow the RunWithParams() expectation -// in ExpectRunAndDelete() to compile. -bool operator==(const Tuple1<PipelineStatus>& lhs, - const Tuple1<PipelineStatus>& rhs) { - return lhs.a == rhs.a; -} - -void MockStatusCallback::ExpectRunAndDelete(PipelineStatus status) { - EXPECT_CALL(*this, RunWithParams(Tuple1<PipelineStatus>(status))); - EXPECT_CALL(*this, Destructor()); -} - -MockCallback* NewExpectedCallback() { +base::Closure NewExpectedCallback() { StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); - callback->ExpectRunAndDelete(); - return callback; -} - -MockStatusCallback* NewExpectedStatusCallback(PipelineStatus status) { - StrictMock<MockStatusCallback>* callback = - new StrictMock<MockStatusCallback>(); - callback->ExpectRunAndDelete(status); - return callback; + EXPECT_CALL(*callback, Run()); + return base::Bind(&MockCallback::Run, callback); } class MockStatusCB : public base::RefCountedThreadSafe<MockStatusCB> { public: MockStatusCB() {} virtual ~MockStatusCB() {} - MOCK_METHOD1(Run, void(PipelineStatus)); - private: DISALLOW_COPY_AND_ASSIGN(MockStatusCB); }; diff --git a/media/base/mock_callback.h b/media/base/mock_callback.h index 3b26df9..adee5c6 100644 --- a/media/base/mock_callback.h +++ b/media/base/mock_callback.h @@ -11,68 +11,20 @@ namespace media { -// Helper class used to test that callbacks are executed. -// -// In most cases NewExpectedCallback() can be used but if need be you can -// manually set expectations on an MockCallback object: -// -// StrictMock<MockCallback>* callback = -// new StrictMock<MockCallback>(); -// EXPECT_CALL(*callback, RunWithParams(_)); -// EXPECT_CALL(*callback, Destructor()); -// -// ...or the equivalent and less verbose: -// StrictMock<MockCallback>* callback = -// new StrictMock<MockCallback>(); -// callback->ExpectRunAndDelete(); -// -// ...or if you don't care about verifying callback deletion: -// -// NiceMock<MockCallback>* callback = -// new NiceMock<MockCallback>(); -// EXPECT_CALL(*callback, RunWithParams(_)); -class MockCallback : public CallbackRunner<Tuple0> { +// Utility class that presents a base::Closure interface (through as_closure()) +// and the ability to set a gMock expectation of being called (through +// ExpectCall). +class MockCallback : public base::RefCountedThreadSafe<MockCallback> { public: MockCallback(); virtual ~MockCallback(); - - MOCK_METHOD1(RunWithParams, void(const Tuple0& params)); - - // Can be used to verify the object is destroyed. - MOCK_METHOD0(Destructor, void()); - - // Convenience function to set expectations for the callback to execute and - // deleted. - void ExpectRunAndDelete(); - + MOCK_METHOD0(Run, void()); private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; -// Helper class similar to MockCallback but is used where a -// PipelineStatusCallback is needed. -class MockStatusCallback : public CallbackRunner<Tuple1<PipelineStatus> > { - public: - MockStatusCallback(); - virtual ~MockStatusCallback(); - - MOCK_METHOD1(RunWithParams, void(const Tuple1<PipelineStatus>& params)); - - // Can be used to verify the object is destroyed. - MOCK_METHOD0(Destructor, void()); - - // Convenience function to set expectations for the callback to execute and - // deleted. - void ExpectRunAndDelete(PipelineStatus status); - - private: - DISALLOW_COPY_AND_ASSIGN(MockStatusCallback); -}; - -// Convenience functions that automatically create and set an expectation for -// the callback to run. -MockCallback* NewExpectedCallback(); -MockStatusCallback* NewExpectedStatusCallback(PipelineStatus status); +// Return a callback that expects to be run once. +base::Closure NewExpectedCallback(); base::Callback<void(PipelineStatus)> NewExpectedStatusCB(PipelineStatus status); } // namespace media diff --git a/media/base/mock_filters.cc b/media/base/mock_filters.cc index 0bdedd3..d398448 100644 --- a/media/base/mock_filters.cc +++ b/media/base/mock_filters.cc @@ -48,12 +48,9 @@ void MockDemuxerFactory::SetError(PipelineStatus error) { } void MockDemuxerFactory::RunBuildCallback(const std::string& url, - BuildCallback* callback) { - scoped_ptr<BuildCallback> cb(callback); - + const BuildCallback& callback) { if (!demuxer_.get()) { - cb->Run(PIPELINE_ERROR_REQUIRED_FILTER_MISSING, - static_cast<Demuxer*>(NULL)); + callback.Run(PIPELINE_ERROR_REQUIRED_FILTER_MISSING, NULL); return; } @@ -61,16 +58,11 @@ void MockDemuxerFactory::RunBuildCallback(const std::string& url, demuxer_ = NULL; if (status_ == PIPELINE_OK) { - cb->Run(PIPELINE_OK, demuxer.get()); + callback.Run(PIPELINE_OK, demuxer.get()); return; } - cb->Run(status_, static_cast<Demuxer*>(NULL)); -} - -void MockDemuxerFactory::DestroyBuildCallback(const std::string& url, - BuildCallback* callback) { - delete callback; + callback.Run(status_, NULL); } DemuxerFactory* MockDemuxerFactory::Clone() const { @@ -146,15 +138,12 @@ FilterCollection* MockFilterCollection::filter_collection( demuxer_factory->SetError(build_status); if (run_build_callback) { - ON_CALL(*demuxer_factory, Build(_, NotNull())).WillByDefault(Invoke( + ON_CALL(*demuxer_factory, Build(_, _)).WillByDefault(Invoke( demuxer_factory, &MockDemuxerFactory::RunBuildCallback)); - } else { - ON_CALL(*demuxer_factory, Build(_, NotNull())).WillByDefault(Invoke( - demuxer_factory, &MockDemuxerFactory::DestroyBuildCallback)); - } + } // else ignore Build calls. if (run_build) - EXPECT_CALL(*demuxer_factory, Build(_, NotNull())); + EXPECT_CALL(*demuxer_factory, Build(_, _)); collection->SetDemuxerFactory(demuxer_factory); collection->AddVideoDecoder(video_decoder_); @@ -164,9 +153,9 @@ FilterCollection* MockFilterCollection::filter_collection( return collection; } -void RunFilterCallback(::testing::Unused, FilterCallback* callback) { - callback->Run(); - delete callback; +void RunFilterCallback(::testing::Unused, const base::Closure& callback) { + callback.Run(); + } void RunFilterStatusCB(::testing::Unused, const FilterStatusCB& cb) { @@ -177,19 +166,14 @@ void RunPipelineStatusCB(PipelineStatus status, const PipelineStatusCB& cb) { cb.Run(status); } -void RunFilterCallback3(::testing::Unused, FilterCallback* callback, +void RunFilterCallback3(::testing::Unused, const base::Closure& callback, ::testing::Unused) { - callback->Run(); - delete callback; -} + callback.Run(); -void DestroyFilterCallback(::testing::Unused, FilterCallback* callback) { - delete callback; } -void RunStopFilterCallback(FilterCallback* callback) { - callback->Run(); - delete callback; +void RunStopFilterCallback(const base::Closure& callback) { + callback.Run(); } MockFilter::MockFilter() { diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index 9b16ff5..d2a8509 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -15,6 +15,7 @@ #include <string> +#include "base/callback.h" #include "media/base/audio_decoder_config.h" #include "media/base/demuxer.h" #include "media/base/filters.h" @@ -51,10 +52,10 @@ class MockFilter : public Filter { MockFilter(); // Filter implementation. - MOCK_METHOD1(Play, void(FilterCallback* callback)); - MOCK_METHOD1(Pause, void(FilterCallback* callback)); - MOCK_METHOD1(Flush, void(FilterCallback* callback)); - MOCK_METHOD1(Stop, void(FilterCallback* callback)); + MOCK_METHOD1(Play, void(const base::Closure& callback)); + MOCK_METHOD1(Pause, void(const base::Closure& callback)); + MOCK_METHOD1(Flush, void(const base::Closure& callback)); + MOCK_METHOD1(Stop, void(const base::Closure& callback)); MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); MOCK_METHOD0(OnAudioRendererDisabled, void()); @@ -73,14 +74,14 @@ class MockDataSource : public DataSource { // Filter implementation. virtual void set_host(FilterHost* host); - MOCK_METHOD1(Stop, void(FilterCallback* callback)); + MOCK_METHOD1(Stop, void(const base::Closure& callback)); MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); MOCK_METHOD0(OnAudioRendererDisabled, void()); // DataSource implementation. MOCK_METHOD4(Read, void(int64 position, size_t size, uint8* data, - DataSource::ReadCallback* callback)); + const DataSource::ReadCallback& callback)); MOCK_METHOD1(GetSize, bool(int64* size_out)); MOCK_METHOD1(SetPreload, void(Preload preload)); MOCK_METHOD1(SetBitrate, void(int bitrate)); @@ -105,7 +106,7 @@ class MockDemuxer : public Demuxer { MockDemuxer(); // Filter implementation. virtual void set_host(FilterHost* host); - MOCK_METHOD1(Stop, void(FilterCallback* callback)); + MOCK_METHOD1(Stop, void(const base::Closure& callback)); MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); MOCK_METHOD1(SetPreload, void(Preload preload)); MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); @@ -113,7 +114,7 @@ class MockDemuxer : public Demuxer { // Demuxer implementation. MOCK_METHOD2(Initialize, void(DataSource* data_source, - FilterCallback* callback)); + const base::Closure& callback)); MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(DemuxerStream::Type)); MOCK_CONST_METHOD0(GetStartTime, base::TimeDelta()); @@ -139,11 +140,11 @@ class MockDemuxerFactory : public DemuxerFactory { virtual ~MockDemuxerFactory(); void SetError(PipelineStatus error); - void RunBuildCallback(const std::string& url, BuildCallback* callback); - void DestroyBuildCallback(const std::string& url, BuildCallback* callback); + void RunBuildCallback(const std::string& url, const BuildCallback& callback); // DemuxerFactory methods. - MOCK_METHOD2(Build, void(const std::string& url, BuildCallback* callback)); + MOCK_METHOD2(Build, void(const std::string& url, + const BuildCallback& callback)); virtual DemuxerFactory* Clone() const; private: @@ -176,15 +177,15 @@ class MockVideoDecoder : public VideoDecoder { MockVideoDecoder(); // Filter implementation. - MOCK_METHOD1(Stop, void(FilterCallback* callback)); + MOCK_METHOD1(Stop, void(const base::Closure& callback)); MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); MOCK_METHOD0(OnAudioRendererDisabled, void()); // VideoDecoder implementation. MOCK_METHOD3(Initialize, void(DemuxerStream* stream, - FilterCallback* callback, - StatisticsCallback* stats_callback)); + const base::Closure& callback, + const StatisticsCallback& stats_callback)); MOCK_METHOD1(ProduceVideoFrame, void(scoped_refptr<VideoFrame>)); MOCK_METHOD0(natural_size, gfx::Size()); @@ -204,15 +205,15 @@ class MockAudioDecoder : public AudioDecoder { MockAudioDecoder(); // Filter implementation. - MOCK_METHOD1(Stop, void(FilterCallback* callback)); + MOCK_METHOD1(Stop, void(const base::Closure& callback)); MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); MOCK_METHOD0(OnAudioRendererDisabled, void()); // AudioDecoder implementation. MOCK_METHOD3(Initialize, void(DemuxerStream* stream, - FilterCallback* callback, - StatisticsCallback* stats_callback)); + const base::Closure& callback, + const StatisticsCallback& stats_callback)); MOCK_METHOD1(ProduceAudioSamples, void(scoped_refptr<Buffer>)); MOCK_METHOD0(bits_per_channel, int(void)); MOCK_METHOD0(channel_layout, ChannelLayout(void)); @@ -234,15 +235,15 @@ class MockVideoRenderer : public VideoRenderer { MockVideoRenderer(); // Filter implementation. - MOCK_METHOD1(Stop, void(FilterCallback* callback)); + MOCK_METHOD1(Stop, void(const base::Closure& callback)); MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); MOCK_METHOD0(OnAudioRendererDisabled, void()); // VideoRenderer implementation. MOCK_METHOD3(Initialize, void(VideoDecoder* decoder, - FilterCallback* callback, - StatisticsCallback* stats_callback)); + const base::Closure& callback, + const StatisticsCallback& stats_callback)); MOCK_METHOD0(HasEnded, bool()); // TODO(scherkus): although VideoRendererBase defines this method, this really @@ -261,14 +262,14 @@ class MockAudioRenderer : public AudioRenderer { MockAudioRenderer(); // Filter implementation. - MOCK_METHOD1(Stop, void(FilterCallback* callback)); + MOCK_METHOD1(Stop, void(const base::Closure& callback)); MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); MOCK_METHOD0(OnAudioRendererDisabled, void()); // AudioRenderer implementation. MOCK_METHOD2(Initialize, void(AudioDecoder* decoder, - FilterCallback* callback)); + const base::Closure& callback)); MOCK_METHOD0(HasEnded, bool()); MOCK_METHOD1(SetVolume, void(float volume)); @@ -313,23 +314,17 @@ class MockFilterCollection { }; // Helper gmock functions that immediately executes and destroys the -// FilterCallback on behalf of the provided filter. Can be used when mocking +// Closure on behalf of the provided filter. Can be used when mocking // the Initialize() and Seek() methods. -void RunFilterCallback(::testing::Unused, FilterCallback* callback); +void RunFilterCallback(::testing::Unused, const base::Closure& callback); void RunFilterStatusCB(::testing::Unused, const FilterStatusCB& cb); void RunPipelineStatusCB(PipelineStatus status, const PipelineStatusCB& cb); -void RunFilterCallback3(::testing::Unused, FilterCallback* callback, +void RunFilterCallback3(::testing::Unused, const base::Closure& callback, ::testing::Unused); -// Helper gmock function that immediately destroys the FilterCallback on behalf -// of the provided filter. Can be used when mocking the Initialize() and Seek() -// methods. -void DestroyFilterCallback(::testing::Unused, FilterCallback* callback); - -// Helper gmock function that immediately executes and destroys the -// FilterCallback on behalf of the provided filter. Can be used when mocking -// the Stop() method. -void RunStopFilterCallback(FilterCallback* callback); +// Helper gmock function that immediately executes the Closure on behalf of the +// provided filter. Can be used when mocking the Stop() method. +void RunStopFilterCallback(const base::Closure& callback); // Helper gmock action that calls SetError() on behalf of the provided filter. ACTION_P2(SetError, filter, error) { diff --git a/media/base/mock_task.h b/media/base/mock_task.h index 6d418a1..53b66b7 100644 --- a/media/base/mock_task.h +++ b/media/base/mock_task.h @@ -45,7 +45,7 @@ // This class is not threadsafe. // // TODO(ajwong): Is it even worth bothering with gmock here? -// TODO(ajwong): Move MockFilterCallback here and merge the implementation +// TODO(ajwong): Move MockCallback here and merge the implementation // differences. #ifndef MEDIA_BASE_MOCK_TASK_H_ diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index 263441c..5f9fb25 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -15,7 +15,6 @@ #include "base/stl_util.h" #include "base/string_util.h" #include "base/synchronization/condition_variable.h" -#include "media/base/callback.h" #include "media/base/clock.h" #include "media/base/filter_collection.h" #include "media/base/media_log.h" @@ -116,11 +115,10 @@ bool PipelineImpl::Start(FilterCollection* collection, running_ = true; message_loop_->PostTask( FROM_HERE, - NewRunnableMethod(this, - &PipelineImpl::StartTask, - filter_collection.release(), - url, - start_callback)); + base::Bind(&PipelineImpl::StartTask, this, + filter_collection.release(), + url, + start_callback)); return true; } @@ -133,7 +131,7 @@ void PipelineImpl::Stop(const PipelineStatusCB& stop_callback) { // Stop the pipeline, which will set |running_| to false on behalf. message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::StopTask, stop_callback)); + base::Bind(&PipelineImpl::StopTask, this, stop_callback)); } void PipelineImpl::Seek(base::TimeDelta time, @@ -145,7 +143,7 @@ void PipelineImpl::Seek(base::TimeDelta time, } message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::SeekTask, time, seek_callback)); + base::Bind(&PipelineImpl::SeekTask, this, time, seek_callback)); } bool PipelineImpl::IsRunning() const { @@ -199,9 +197,8 @@ void PipelineImpl::SetPlaybackRate(float playback_rate) { base::AutoLock auto_lock(lock_); playback_rate_ = playback_rate; if (running_) { - message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::PlaybackRateChangedTask, - playback_rate)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &PipelineImpl::PlaybackRateChangedTask, this, playback_rate)); } } @@ -218,9 +215,8 @@ void PipelineImpl::SetVolume(float volume) { base::AutoLock auto_lock(lock_); volume_ = volume; if (running_) { - message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::VolumeChangedTask, - volume)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &PipelineImpl::VolumeChangedTask, this, volume)); } } @@ -233,9 +229,8 @@ void PipelineImpl::SetPreload(Preload preload) { base::AutoLock auto_lock(lock_); preload_ = preload; if (running_) { - message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::PreloadChangedTask, - preload)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &PipelineImpl::PreloadChangedTask, this, preload)); } } @@ -465,7 +460,7 @@ void PipelineImpl::SetError(PipelineStatus error) { VLOG(1) << "Media pipeline error: " << error; message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::ErrorChangedTask, error)); + base::Bind(&PipelineImpl::ErrorChangedTask, this, error)); media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(error)); } @@ -555,7 +550,7 @@ void PipelineImpl::SetStreaming(bool streaming) { void PipelineImpl::NotifyEnded() { DCHECK(IsRunning()); message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::NotifyEndedTask)); + base::Bind(&PipelineImpl::NotifyEndedTask, this)); media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::ENDED)); } @@ -576,7 +571,7 @@ void PipelineImpl::SetNetworkActivity(bool network_activity) { network_activity_ = network_activity; } message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::NotifyNetworkEventTask)); + base::Bind(&PipelineImpl::NotifyNetworkEventTask, this)); media_log_->AddEvent( media_log_->CreateBooleanEvent( MediaLogEvent::NETWORK_ACTIVITY_SET, @@ -588,7 +583,7 @@ void PipelineImpl::DisableAudioRenderer() { // Disable renderer on the message loop. message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::DisableAudioRendererTask)); + base::Bind(&PipelineImpl::DisableAudioRendererTask, this)); media_log_->AddEvent( media_log_->CreateEvent(MediaLogEvent::AUDIO_RENDERER_DISABLED)); } @@ -597,22 +592,22 @@ void PipelineImpl::DisableAudioRenderer() { void PipelineImpl::OnFilterInitialize() { // Continue the initialize task by proceeding to the next stage. message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::InitializeTask)); + base::Bind(&PipelineImpl::InitializeTask, this)); } // Called from any thread. void PipelineImpl::OnFilterStateTransition() { message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::FilterStateTransitionTask)); + base::Bind(&PipelineImpl::FilterStateTransitionTask, this)); } // Called from any thread. -// This method makes the FilterStatusCB behave like a FilterCallback. It +// This method makes the FilterStatusCB behave like a Closure. It // makes it look like a host()->SetError() call followed by a call to // OnFilterStateTransition() when errors occur. // // TODO: Revisit this code when SetError() is removed from FilterHost and -// all the FilterCallbacks are converted to FilterStatusCB. +// all the Closures are converted to FilterStatusCB. void PipelineImpl::OnFilterStateTransitionWithStatus(PipelineStatus status) { if (status != PIPELINE_OK) SetError(status); @@ -621,7 +616,7 @@ void PipelineImpl::OnFilterStateTransitionWithStatus(PipelineStatus status) { void PipelineImpl::OnTeardownStateTransition() { message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::TeardownStateTransitionTask)); + base::Bind(&PipelineImpl::TeardownStateTransitionTask, this)); } // Called from any thread. @@ -817,7 +812,7 @@ void PipelineImpl::ErrorChangedTask(PipelineStatus error) { // don't modify the state before TeadDownPipeline() can run. tearing_down_ = true; message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::TearDownPipeline)); + base::Bind(&PipelineImpl::TearDownPipeline, this)); } void PipelineImpl::PlaybackRateChangedTask(float playback_rate) { @@ -895,7 +890,7 @@ void PipelineImpl::SeekTask(base::TimeDelta time, clock_->Pause(); } pipeline_filter_->Pause( - NewCallback(this, &PipelineImpl::OnFilterStateTransition)); + base::Bind(&PipelineImpl::OnFilterStateTransition, this)); } void PipelineImpl::NotifyEndedTask() { @@ -989,17 +984,17 @@ void PipelineImpl::FilterStateTransitionTask() { if (TransientState(state_)) { if (state_ == kPausing) { pipeline_filter_->Pause( - NewCallback(this, &PipelineImpl::OnFilterStateTransition)); + base::Bind(&PipelineImpl::OnFilterStateTransition, this)); } else if (state_ == kFlushing) { pipeline_filter_->Flush( - NewCallback(this, &PipelineImpl::OnFilterStateTransition)); + base::Bind(&PipelineImpl::OnFilterStateTransition, this)); } else if (state_ == kSeeking) { DoSeek(seek_timestamp_); } else if (state_ == kStarting) { pipeline_filter_->Play( - NewCallback(this, &PipelineImpl::OnFilterStateTransition)); + base::Bind(&PipelineImpl::OnFilterStateTransition, this)); } else if (state_ == kStopping) { - DoStop(NewCallback(this, &PipelineImpl::OnFilterStateTransition)); + DoStop(base::Bind(&PipelineImpl::OnFilterStateTransition, this)); } else { NOTREACHED() << "Unexpected state: " << state_; } @@ -1043,11 +1038,11 @@ void PipelineImpl::TeardownStateTransitionTask() { case kPausing: SetState(kFlushing); pipeline_filter_->Flush( - NewCallback(this, &PipelineImpl::OnTeardownStateTransition)); + base::Bind(&PipelineImpl::OnTeardownStateTransition, this)); break; case kFlushing: SetState(kStopping); - DoStop(NewCallback(this, &PipelineImpl::OnTeardownStateTransition)); + DoStop(base::Bind(&PipelineImpl::OnTeardownStateTransition, this)); break; case kCreated: @@ -1111,17 +1106,16 @@ void PipelineImpl::InitializeDemuxer() { DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK(IsPipelineOk()); - filter_collection_->GetDemuxerFactory()->Build(url_, - NewCallback(this, &PipelineImpl::OnDemuxerBuilt)); + filter_collection_->GetDemuxerFactory()->Build( + url_, base::Bind(&PipelineImpl::OnDemuxerBuilt, this)); } void PipelineImpl::OnDemuxerBuilt(PipelineStatus status, Demuxer* demuxer) { if (MessageLoop::current() != message_loop_) { message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &PipelineImpl::OnDemuxerBuilt, - status, - make_scoped_refptr(demuxer))); + base::Bind(&PipelineImpl::OnDemuxerBuilt, this, + status, + make_scoped_refptr(demuxer))); return; } @@ -1173,8 +1167,8 @@ bool PipelineImpl::InitializeAudioDecoder( pipeline_init_state_->audio_decoder_ = audio_decoder; audio_decoder->Initialize( stream, - NewCallback(this, &PipelineImpl::OnFilterInitialize), - NewCallback(this, &PipelineImpl::OnUpdateStatistics)); + base::Bind(&PipelineImpl::OnFilterInitialize, this), + base::Bind(&PipelineImpl::OnUpdateStatistics, this)); return true; } @@ -1206,8 +1200,8 @@ bool PipelineImpl::InitializeVideoDecoder( pipeline_init_state_->video_decoder_ = video_decoder; video_decoder->Initialize( stream, - NewCallback(this, &PipelineImpl::OnFilterInitialize), - NewCallback(this, &PipelineImpl::OnUpdateStatistics)); + base::Bind(&PipelineImpl::OnFilterInitialize, this), + base::Bind(&PipelineImpl::OnUpdateStatistics, this)); return true; } @@ -1229,7 +1223,7 @@ bool PipelineImpl::InitializeAudioRenderer( return false; audio_renderer_->Initialize( - decoder, NewCallback(this, &PipelineImpl::OnFilterInitialize)); + decoder, base::Bind(&PipelineImpl::OnFilterInitialize, this)); return true; } @@ -1252,8 +1246,8 @@ bool PipelineImpl::InitializeVideoRenderer( video_renderer_->Initialize( decoder, - NewCallback(this, &PipelineImpl::OnFilterInitialize), - NewCallback(this, &PipelineImpl::OnUpdateStatistics)); + base::Bind(&PipelineImpl::OnFilterInitialize, this), + base::Bind(&PipelineImpl::OnUpdateStatistics, this)); return true; } @@ -1275,7 +1269,7 @@ void PipelineImpl::TearDownPipeline() { // Need to put this in the message loop to make sure that it comes // after any pending callback tasks that are already queued. message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &PipelineImpl::FinishDestroyingFiltersTask)); + base::Bind(&PipelineImpl::FinishDestroyingFiltersTask, this)); break; case kInitDemuxer: @@ -1289,7 +1283,7 @@ void PipelineImpl::TearDownPipeline() { filter_collection_.reset(); SetState(kStopping); - DoStop(NewCallback(this, &PipelineImpl::OnTeardownStateTransition)); + DoStop(base::Bind(&PipelineImpl::OnTeardownStateTransition, this)); FinishInitialization(); break; @@ -1299,7 +1293,7 @@ void PipelineImpl::TearDownPipeline() { case kFlushing: case kStarting: SetState(kStopping); - DoStop(NewCallback(this, &PipelineImpl::OnTeardownStateTransition)); + DoStop(base::Bind(&PipelineImpl::OnTeardownStateTransition, this)); if (seek_pending_) { seek_pending_ = false; @@ -1312,7 +1306,7 @@ void PipelineImpl::TearDownPipeline() { case kEnded: SetState(kPausing); pipeline_filter_->Pause( - NewCallback(this, &PipelineImpl::OnTeardownStateTransition)); + base::Bind(&PipelineImpl::OnTeardownStateTransition, this)); break; case kStopping: @@ -1324,24 +1318,24 @@ void PipelineImpl::TearDownPipeline() { }; } -void PipelineImpl::DoStop(FilterCallback* callback) { +void PipelineImpl::DoStop(const base::Closure& callback) { if (demuxer_) { - demuxer_->Stop(NewCallbackForClosure( - base::Bind(&PipelineImpl::OnDemuxerStopDone, this, callback))); + demuxer_->Stop(base::Bind( + &PipelineImpl::OnDemuxerStopDone, this, callback)); return; } OnDemuxerStopDone(callback); } -void PipelineImpl::OnDemuxerStopDone(FilterCallback* callback) { +void PipelineImpl::OnDemuxerStopDone(const base::Closure& callback) { if (pipeline_filter_) { pipeline_filter_->Stop(callback); return; } - callback->Run(); - delete callback; + callback.Run(); + } void PipelineImpl::DoSeek(base::TimeDelta seek_timestamp) { diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index d792347..c4c9898 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -319,11 +319,11 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline, public FilterHost { // Initiates a Stop() on |demuxer_| & |pipeline_filter_|. |callback| // is called once both objects have been stopped. - void DoStop(FilterCallback* callback); + void DoStop(const base::Closure& callback); // Called when |demuxer_| has stopped. This method calls Stop() // on |pipeline_filter_|. - void OnDemuxerStopDone(FilterCallback* callback); + void OnDemuxerStopDone(const base::Closure& callback); // Initiates a Seek() on the |demuxer_| & |pipeline_filter_|. void DoSeek(base::TimeDelta seek_timestamp); diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc index c1cd68d..0abd9c4 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -103,7 +103,7 @@ class PipelineImplTest : public ::testing::Test { EXPECT_CALL(*mocks_->demuxer(), SetPreload(AUTO)); EXPECT_CALL(*mocks_->demuxer(), Seek(mocks_->demuxer()->GetStartTime(), _)) .WillOnce(Invoke(&RunFilterStatusCB)); - EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull())) + EXPECT_CALL(*mocks_->demuxer(), Stop(_)) .WillOnce(Invoke(&RunStopFilterCallback)); // Configure the demuxer to return the streams. @@ -125,38 +125,37 @@ class PipelineImplTest : public ::testing::Test { // Sets up expectations to allow the video decoder to initialize. void InitializeVideoDecoder(MockDemuxerStream* stream) { EXPECT_CALL(*mocks_->video_decoder(), - Initialize(stream, NotNull(), NotNull())) - .WillOnce(DoAll(Invoke(&RunFilterCallback3), DeleteArg<2>())); + Initialize(stream, _, _)) + .WillOnce(Invoke(&RunFilterCallback3)); EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->video_decoder(), Seek(mocks_->demuxer()->GetStartTime(), _)) .WillOnce(Invoke(&RunFilterStatusCB)); - EXPECT_CALL(*mocks_->video_decoder(), Stop(NotNull())) + EXPECT_CALL(*mocks_->video_decoder(), Stop(_)) .WillOnce(Invoke(&RunStopFilterCallback)); } // Sets up expectations to allow the audio decoder to initialize. void InitializeAudioDecoder(MockDemuxerStream* stream) { - EXPECT_CALL(*mocks_->audio_decoder(), - Initialize(stream, NotNull(), NotNull())) - .WillOnce(DoAll(Invoke(&RunFilterCallback3), DeleteArg<2>())); + EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) + .WillOnce(Invoke(&RunFilterCallback3)); EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->audio_decoder(), Seek(base::TimeDelta(), _)) .WillOnce(Invoke(&RunFilterStatusCB)); - EXPECT_CALL(*mocks_->audio_decoder(), Stop(NotNull())) + EXPECT_CALL(*mocks_->audio_decoder(), Stop(_)) .WillOnce(Invoke(&RunStopFilterCallback)); } // Sets up expectations to allow the video renderer to initialize. void InitializeVideoRenderer() { EXPECT_CALL(*mocks_->video_renderer(), - Initialize(mocks_->video_decoder(), NotNull(), NotNull())) - .WillOnce(DoAll(Invoke(&RunFilterCallback3), DeleteArg<2>())); + Initialize(mocks_->video_decoder(), _, _)) + .WillOnce(Invoke(&RunFilterCallback3)); EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->video_renderer(), Seek(mocks_->demuxer()->GetStartTime(), _)) .WillOnce(Invoke(&RunFilterStatusCB)); - EXPECT_CALL(*mocks_->video_renderer(), Stop(NotNull())) + EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) .WillOnce(Invoke(&RunStopFilterCallback)); } @@ -164,19 +163,19 @@ class PipelineImplTest : public ::testing::Test { void InitializeAudioRenderer(bool disable_after_init_callback = false) { if (disable_after_init_callback) { EXPECT_CALL(*mocks_->audio_renderer(), - Initialize(mocks_->audio_decoder(), NotNull())) + Initialize(mocks_->audio_decoder(), _)) .WillOnce(DoAll(Invoke(&RunFilterCallback), DisableAudioRenderer(mocks_->audio_renderer()))); } else { EXPECT_CALL(*mocks_->audio_renderer(), - Initialize(mocks_->audio_decoder(), NotNull())) + Initialize(mocks_->audio_decoder(), _)) .WillOnce(Invoke(&RunFilterCallback)); } EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), _)) .WillOnce(Invoke(&RunFilterStatusCB)); - EXPECT_CALL(*mocks_->audio_renderer(), Stop(NotNull())) + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) .WillOnce(Invoke(&RunStopFilterCallback)); } @@ -373,7 +372,7 @@ TEST_F(PipelineImplTest, URLNotFound) { TEST_F(PipelineImplTest, NoStreams) { // Manually set these expectations because SetPlaybackRate() is not called if // we cannot fully initialize the pipeline. - EXPECT_CALL(*mocks_->demuxer(), Stop(NotNull())) + EXPECT_CALL(*mocks_->demuxer(), Stop(_)) .WillOnce(Invoke(&RunStopFilterCallback)); // TODO(acolwell,fischman): see TODO in URLNotFound above. EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_COULD_NOT_RENDER)); diff --git a/media/filters/audio_renderer_algorithm_base.cc b/media/filters/audio_renderer_algorithm_base.cc index df83649..0fd074f 100644 --- a/media/filters/audio_renderer_algorithm_base.cc +++ b/media/filters/audio_renderer_algorithm_base.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -24,11 +24,12 @@ AudioRendererAlgorithmBase::AudioRendererAlgorithmBase() AudioRendererAlgorithmBase::~AudioRendererAlgorithmBase() {} -void AudioRendererAlgorithmBase::Initialize(int channels, - int sample_rate, - int sample_bits, - float initial_playback_rate, - RequestReadCallback* callback) { +void AudioRendererAlgorithmBase::Initialize( + int channels, + int sample_rate, + int sample_bits, + float initial_playback_rate, + const base::Closure& callback) { DCHECK_GT(channels, 0); DCHECK_LE(channels, 8) << "We only support <= 8 channel audio."; DCHECK_GT(sample_rate, 0); @@ -37,12 +38,12 @@ void AudioRendererAlgorithmBase::Initialize(int channels, DCHECK_GT(sample_bits, 0); DCHECK_LE(sample_bits, 32) << "We only support 8, 16, 32 bit audio."; DCHECK_EQ(sample_bits % 8, 0) << "We only support 8, 16, 32 bit audio."; - DCHECK(callback); + DCHECK(!callback.is_null()); channels_ = channels; sample_rate_ = sample_rate; sample_bytes_ = sample_bits / 8; - request_read_callback_.reset(callback); + request_read_callback_ = callback; set_playback_rate(initial_playback_rate); } @@ -50,7 +51,7 @@ void AudioRendererAlgorithmBase::Initialize(int channels, void AudioRendererAlgorithmBase::FlushBuffers() { // Clear the queue of decoded packets (releasing the buffers). queue_.Clear(); - request_read_callback_->Run(); + request_read_callback_.Run(); } base::TimeDelta AudioRendererAlgorithmBase::GetTime() { @@ -64,7 +65,7 @@ void AudioRendererAlgorithmBase::EnqueueBuffer(Buffer* buffer_in) { // If we still don't have enough data, request more. if (!IsQueueFull()) - request_read_callback_->Run(); + request_read_callback_.Run(); } float AudioRendererAlgorithmBase::playback_rate() { @@ -92,7 +93,7 @@ void AudioRendererAlgorithmBase::AdvanceInputPosition(uint32 bytes) { queue_.Seek(bytes); if (!IsQueueFull()) - request_read_callback_->Run(); + request_read_callback_.Run(); } uint32 AudioRendererAlgorithmBase::CopyFromInput(uint8* dest, uint32 bytes) { diff --git a/media/filters/audio_renderer_algorithm_base.h b/media/filters/audio_renderer_algorithm_base.h index e35e209..f244fc9 100644 --- a/media/filters/audio_renderer_algorithm_base.h +++ b/media/filters/audio_renderer_algorithm_base.h @@ -25,7 +25,7 @@ #include <deque> -#include "base/callback_old.h" +#include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "media/base/seekable_buffer.h" @@ -36,9 +36,6 @@ class Buffer; class MEDIA_EXPORT AudioRendererAlgorithmBase { public: - // Used to simplify callback declarations. - typedef Callback0::Type RequestReadCallback; - AudioRendererAlgorithmBase(); virtual ~AudioRendererAlgorithmBase(); @@ -47,7 +44,7 @@ class MEDIA_EXPORT AudioRendererAlgorithmBase { int sample_rate, int sample_bits, float initial_playback_rate, - RequestReadCallback* callback); + const base::Closure& callback); // Implement this strategy method in derived classes. Tries to fill |length| // bytes of |dest| with possibly scaled data from our |queue_|. Returns the @@ -105,7 +102,7 @@ class MEDIA_EXPORT AudioRendererAlgorithmBase { float playback_rate_; // Used to request more data. - scoped_ptr<RequestReadCallback> request_read_callback_; + base::Closure request_read_callback_; // Queued audio data. SeekableBuffer queue_; diff --git a/media/filters/audio_renderer_algorithm_ola_unittest.cc b/media/filters/audio_renderer_algorithm_ola_unittest.cc index 3de796e..39d89c3 100644 --- a/media/filters/audio_renderer_algorithm_ola_unittest.cc +++ b/media/filters/audio_renderer_algorithm_ola_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -8,6 +8,7 @@ // correct rate. We always pass in a very large destination buffer with the // expectation that FillBuffer() will fill as much as it can but no more. +#include "base/bind.h" #include "base/callback.h" #include "media/base/data_buffer.h" #include "media/filters/audio_renderer_algorithm_ola.h" @@ -37,7 +38,8 @@ TEST(AudioRendererAlgorithmOLATest, FillBuffer_NormalRate) { MockDataProvider mock; AudioRendererAlgorithmOLA algorithm; algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 1.0f, - NewCallback(&mock, &MockDataProvider::Read)); + base::Bind(&MockDataProvider::Read, + base::Unretained(&mock))); // We won't reply to any read requests. EXPECT_CALL(mock, Read()).Times(AnyNumber()); @@ -58,7 +60,8 @@ TEST(AudioRendererAlgorithmOLATest, FillBuffer_DoubleRate) { MockDataProvider mock; AudioRendererAlgorithmOLA algorithm; algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 2.0f, - NewCallback(&mock, &MockDataProvider::Read)); + base::Bind(&MockDataProvider::Read, + base::Unretained(&mock))); // We won't reply to any read requests. EXPECT_CALL(mock, Read()).Times(AnyNumber()); @@ -94,7 +97,8 @@ TEST(AudioRendererAlgorithmOLATest, FillBuffer_HalfRate) { MockDataProvider mock; AudioRendererAlgorithmOLA algorithm; algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 0.5f, - NewCallback(&mock, &MockDataProvider::Read)); + base::Bind(&MockDataProvider::Read, + base::Unretained(&mock))); // We won't reply to any read requests. EXPECT_CALL(mock, Read()).Times(AnyNumber()); @@ -130,7 +134,8 @@ TEST(AudioRendererAlgorithmOLATest, FillBuffer_QuarterRate) { MockDataProvider mock; AudioRendererAlgorithmOLA algorithm; algorithm.Initialize(kChannels, kSampleRate, kSampleBits, 0.25f, - NewCallback(&mock, &MockDataProvider::Read)); + base::Bind(&MockDataProvider::Read, + base::Unretained(&mock))); // We won't reply to any read requests. EXPECT_CALL(mock, Read()).Times(AnyNumber()); diff --git a/media/filters/audio_renderer_base.cc b/media/filters/audio_renderer_base.cc index 10ad5ea..f942ed4 100644 --- a/media/filters/audio_renderer_base.cc +++ b/media/filters/audio_renderer_base.cc @@ -28,39 +28,37 @@ AudioRendererBase::~AudioRendererBase() { DCHECK(!algorithm_.get()); } -void AudioRendererBase::Play(FilterCallback* callback) { +void AudioRendererBase::Play(const base::Closure& callback) { base::AutoLock auto_lock(lock_); DCHECK_EQ(kPaused, state_); - scoped_ptr<FilterCallback> c(callback); state_ = kPlaying; - callback->Run(); + callback.Run(); } -void AudioRendererBase::Pause(FilterCallback* callback) { +void AudioRendererBase::Pause(const base::Closure& callback) { base::AutoLock auto_lock(lock_); DCHECK_EQ(kPlaying, state_); - pause_callback_.reset(callback); + pause_callback_ = callback; state_ = kPaused; // We'll only pause when we've finished all pending reads. if (pending_reads_ == 0) { - pause_callback_->Run(); - pause_callback_.reset(); + pause_callback_.Run(); + pause_callback_.Reset(); } else { state_ = kPaused; } } -void AudioRendererBase::Stop(FilterCallback* callback) { +void AudioRendererBase::Stop(const base::Closure& callback) { OnStop(); { base::AutoLock auto_lock(lock_); state_ = kStopped; algorithm_.reset(NULL); } - if (callback) { - callback->Run(); - delete callback; + if (!callback.is_null()) { + callback.Run(); } } @@ -83,11 +81,10 @@ void AudioRendererBase::Seek(base::TimeDelta time, const FilterStatusCB& cb) { } void AudioRendererBase::Initialize(AudioDecoder* decoder, - FilterCallback* callback) { + const base::Closure& callback) { DCHECK(decoder); - DCHECK(callback); + DCHECK(!callback.is_null()); DCHECK_EQ(kUninitialized, state_); - scoped_ptr<FilterCallback> c(callback); decoder_ = decoder; // Use base::Unretained() as the decoder doesn't need to ref us. @@ -96,8 +93,7 @@ void AudioRendererBase::Initialize(AudioDecoder* decoder, base::Unretained(this))); // Create a callback so our algorithm can request more reads. - AudioRendererAlgorithmBase::RequestReadCallback* cb = - NewCallback(this, &AudioRendererBase::ScheduleRead_Locked); + base::Closure cb = base::Bind(&AudioRendererBase::ScheduleRead_Locked, this); // Construct the algorithm. algorithm_.reset(new AudioRendererAlgorithmOLA()); @@ -113,13 +109,13 @@ void AudioRendererBase::Initialize(AudioDecoder* decoder, // Give the subclass an opportunity to initialize itself. if (!OnInitialize(bits_per_channel, channel_layout, sample_rate)) { host()->SetError(PIPELINE_ERROR_INITIALIZATION_FAILED); - callback->Run(); + callback.Run(); return; } // Finally, execute the start callback. state_ = kPaused; - callback->Run(); + callback.Run(); } bool AudioRendererBase::HasEnded() { @@ -168,9 +164,9 @@ void AudioRendererBase::ConsumeAudioSamples(scoped_refptr<Buffer> buffer_in) { } } else if (state_ == kPaused && pending_reads_ == 0) { // No more pending reads! We're now officially "paused". - if (pause_callback_.get()) { - pause_callback_->Run(); - pause_callback_.reset(); + if (!pause_callback_.is_null()) { + pause_callback_.Run(); + pause_callback_.Reset(); } } } diff --git a/media/filters/audio_renderer_base.h b/media/filters/audio_renderer_base.h index cf73924..aedbec7 100644 --- a/media/filters/audio_renderer_base.h +++ b/media/filters/audio_renderer_base.h @@ -33,14 +33,14 @@ class MEDIA_EXPORT AudioRendererBase : public AudioRenderer { virtual ~AudioRendererBase(); // Filter implementation. - virtual void Play(FilterCallback* callback); - virtual void Pause(FilterCallback* callback); - virtual void Stop(FilterCallback* callback); + virtual void Play(const base::Closure& callback); + virtual void Pause(const base::Closure& callback); + virtual void Stop(const base::Closure& callback); virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb); // AudioRenderer implementation. - virtual void Initialize(AudioDecoder* decoder, FilterCallback* callback); + virtual void Initialize(AudioDecoder* decoder, const base::Closure& callback); virtual bool HasEnded(); protected: @@ -126,7 +126,7 @@ class MEDIA_EXPORT AudioRendererBase : public AudioRenderer { base::TimeDelta last_fill_buffer_time_; // Filter callbacks. - scoped_ptr<FilterCallback> pause_callback_; + base::Closure pause_callback_; FilterStatusCB seek_cb_; base::TimeDelta seek_timestamp_; diff --git a/media/filters/chunk_demuxer.cc b/media/filters/chunk_demuxer.cc index ef4f792..ea066d8 100644 --- a/media/filters/chunk_demuxer.cc +++ b/media/filters/chunk_demuxer.cc @@ -233,7 +233,7 @@ static void RunOnMessageLoop(const DemuxerStream::ReadCallback& read_callback, Buffer* buffer) { if (MessageLoop::current() != message_loop) { message_loop->PostTask(FROM_HERE, - NewRunnableFunction(&RunOnMessageLoop, + base::Bind(&RunOnMessageLoop, read_callback, message_loop, scoped_refptr<Buffer>(buffer))); @@ -316,7 +316,7 @@ ChunkDemuxer::~ChunkDemuxer() { } } -void ChunkDemuxer::Init(PipelineStatusCB cb) { +void ChunkDemuxer::Init(const PipelineStatusCB& cb) { VLOG(1) << "Init()"; { base::AutoLock auto_lock(lock_); @@ -335,13 +335,10 @@ void ChunkDemuxer::set_host(FilterHost* filter_host) { filter_host->SetCurrentReadPosition(0); } -void ChunkDemuxer::Stop(FilterCallback* callback) { +void ChunkDemuxer::Stop(const base::Closure& callback) { VLOG(1) << "Stop()"; - Shutdown(); - - callback->Run(); - delete callback; + callback.Run(); } void ChunkDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { diff --git a/media/filters/chunk_demuxer.h b/media/filters/chunk_demuxer.h index a6c2d2a..14f6fb5 100644 --- a/media/filters/chunk_demuxer.h +++ b/media/filters/chunk_demuxer.h @@ -26,11 +26,11 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer { explicit ChunkDemuxer(ChunkDemuxerClient* client); virtual ~ChunkDemuxer(); - void Init(PipelineStatusCB cb); + void Init(const PipelineStatusCB& cb); // Demuxer implementation. virtual void set_host(FilterHost* filter_host) OVERRIDE; - virtual void Stop(FilterCallback* callback) OVERRIDE; + virtual void Stop(const base::Closure& callback) OVERRIDE; virtual void Seek(base::TimeDelta time, const PipelineStatusCB& cb) OVERRIDE; virtual void OnAudioRendererDisabled() OVERRIDE; virtual scoped_refptr<DemuxerStream> GetStream(DemuxerStream::Type type); diff --git a/media/filters/chunk_demuxer_factory.cc b/media/filters/chunk_demuxer_factory.cc index ed3346c..7887494 100644 --- a/media/filters/chunk_demuxer_factory.cc +++ b/media/filters/chunk_demuxer_factory.cc @@ -10,24 +10,23 @@ namespace media { -static void DoInitDone(DemuxerFactory::BuildCallback* cb, +static void DoInitDone(const DemuxerFactory::BuildCallback& cb, const scoped_refptr<Demuxer>& demuxer, PipelineStatus status) { - scoped_ptr<DemuxerFactory::BuildCallback> callback(cb); if (status != PIPELINE_OK) { - callback->Run(status, static_cast<Demuxer*>(NULL)); + cb.Run(status, static_cast<Demuxer*>(NULL)); return; } - callback->Run(status, demuxer); + cb.Run(status, demuxer); } static void InitDone(MessageLoop* message_loop, - DemuxerFactory::BuildCallback* cb, + const DemuxerFactory::BuildCallback& cb, const scoped_refptr<Demuxer>& demuxer, PipelineStatus status) { message_loop->PostTask(FROM_HERE, - NewRunnableFunction(&DoInitDone, cb, demuxer, status)); + base::Bind(&DoInitDone, cb, demuxer, status)); } ChunkDemuxerFactory::ChunkDemuxerFactory(const std::string& url, @@ -41,7 +40,8 @@ ChunkDemuxerFactory::ChunkDemuxerFactory(const std::string& url, ChunkDemuxerFactory::~ChunkDemuxerFactory() {} -void ChunkDemuxerFactory::Build(const std::string& url, BuildCallback* cb) { +void ChunkDemuxerFactory::Build(const std::string& url, + const BuildCallback& cb) { // Check to see if this is the URL we are looking for. If not delegate // building to the delegate factory. if (url != url_) { @@ -52,8 +52,7 @@ void ChunkDemuxerFactory::Build(const std::string& url, BuildCallback* cb) { scoped_refptr<ChunkDemuxer> demuxer(new ChunkDemuxer(client_)); // Call Init() on demuxer. Note that ownership is being passed to the // callback here. - demuxer->Init(base::Bind(&InitDone, MessageLoop::current(), cb, - scoped_refptr<Demuxer>(demuxer.get()))); + demuxer->Init(base::Bind(&InitDone, MessageLoop::current(), cb, demuxer)); } DemuxerFactory* ChunkDemuxerFactory::Clone() const { diff --git a/media/filters/chunk_demuxer_factory.h b/media/filters/chunk_demuxer_factory.h index fec6a04..beab479 100644 --- a/media/filters/chunk_demuxer_factory.h +++ b/media/filters/chunk_demuxer_factory.h @@ -28,7 +28,7 @@ class MEDIA_EXPORT ChunkDemuxerFactory : public DemuxerFactory { virtual ~ChunkDemuxerFactory(); // DemuxerFactory methods. - virtual void Build(const std::string& url, BuildCallback* cb); + virtual void Build(const std::string& url, const BuildCallback& cb); virtual DemuxerFactory* Clone() const; private: diff --git a/media/filters/dummy_demuxer_factory.cc b/media/filters/dummy_demuxer_factory.cc index e61c969..37495e8 100644 --- a/media/filters/dummy_demuxer_factory.cc +++ b/media/filters/dummy_demuxer_factory.cc @@ -16,11 +16,11 @@ DummyDemuxerFactory::DummyDemuxerFactory(bool has_video, bool has_audio) DummyDemuxerFactory::~DummyDemuxerFactory() {} -void DummyDemuxerFactory::Build(const std::string& url, BuildCallback* cb) { +void DummyDemuxerFactory::Build(const std::string& url, + const BuildCallback& cb) { scoped_refptr<DummyDemuxer> demuxer = new DummyDemuxer(has_video_, has_audio_); - scoped_ptr<DemuxerFactory::BuildCallback> callback(cb); - callback->Run(PIPELINE_OK, demuxer.get()); + cb.Run(PIPELINE_OK, demuxer.get()); } DemuxerFactory* DummyDemuxerFactory::Clone() const { diff --git a/media/filters/dummy_demuxer_factory.h b/media/filters/dummy_demuxer_factory.h index 7fe0867..6662799 100644 --- a/media/filters/dummy_demuxer_factory.h +++ b/media/filters/dummy_demuxer_factory.h @@ -18,7 +18,7 @@ class MEDIA_EXPORT DummyDemuxerFactory : public DemuxerFactory { virtual ~DummyDemuxerFactory(); // DemuxerFactory methods. - virtual void Build(const std::string& url, BuildCallback* cb) OVERRIDE; + virtual void Build(const std::string& url, const BuildCallback& cb) OVERRIDE; virtual DemuxerFactory* Clone() const OVERRIDE; private: diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc index d2086a8..dca4bfa 100644 --- a/media/filters/ffmpeg_audio_decoder.cc +++ b/media/filters/ffmpeg_audio_decoder.cc @@ -67,30 +67,30 @@ FFmpegAudioDecoder::~FFmpegAudioDecoder() { } } -void FFmpegAudioDecoder::Flush(FilterCallback* callback) { +void FFmpegAudioDecoder::Flush(const base::Closure& callback) { message_loop_->PostTask( FROM_HERE, - NewRunnableMethod(this, &FFmpegAudioDecoder::DoFlush, callback)); + base::Bind(&FFmpegAudioDecoder::DoFlush, this, callback)); } void FFmpegAudioDecoder::Initialize( DemuxerStream* stream, - FilterCallback* callback, - StatisticsCallback* stats_callback) { + const base::Closure& callback, + const StatisticsCallback& stats_callback) { // TODO(scherkus): change Initialize() signature to pass |stream| as a // scoped_refptr<>. scoped_refptr<DemuxerStream> ref_stream(stream); message_loop_->PostTask( FROM_HERE, - NewRunnableMethod(this, &FFmpegAudioDecoder::DoInitialize, - ref_stream, callback, stats_callback)); + base::Bind(&FFmpegAudioDecoder::DoInitialize, this, + ref_stream, callback, stats_callback)); } void FFmpegAudioDecoder::ProduceAudioSamples(scoped_refptr<Buffer> buffer) { message_loop_->PostTask( FROM_HERE, - NewRunnableMethod(this, &FFmpegAudioDecoder::DoProduceAudioSamples, - buffer)); + base::Bind(&FFmpegAudioDecoder::DoProduceAudioSamples, this, + buffer)); } int FFmpegAudioDecoder::bits_per_channel() { @@ -107,13 +107,11 @@ int FFmpegAudioDecoder::samples_per_second() { void FFmpegAudioDecoder::DoInitialize( const scoped_refptr<DemuxerStream>& stream, - FilterCallback* callback, - StatisticsCallback* stats_callback) { - scoped_ptr<FilterCallback> c(callback); - + const base::Closure& callback, + const StatisticsCallback& stats_callback) { demuxer_stream_ = stream; const AudioDecoderConfig& config = stream->audio_decoder_config(); - stats_callback_.reset(stats_callback); + stats_callback_ = stats_callback; // TODO(scherkus): this check should go in PipelineImpl prior to creating // decoder objects. @@ -125,7 +123,7 @@ void FFmpegAudioDecoder::DoInitialize( << " samples per second: " << config.samples_per_second(); host()->SetError(DECODER_ERROR_NOT_SUPPORTED); - callback->Run(); + callback.Run(); return; } @@ -139,7 +137,7 @@ void FFmpegAudioDecoder::DoInitialize( << codec_context_->codec_id; host()->SetError(DECODER_ERROR_NOT_SUPPORTED); - callback->Run(); + callback.Run(); return; } @@ -148,15 +146,13 @@ void FFmpegAudioDecoder::DoInitialize( channel_layout_ = config.channel_layout(); samples_per_second_ = config.samples_per_second(); - callback->Run(); + callback.Run(); } -void FFmpegAudioDecoder::DoFlush(FilterCallback* callback) { +void FFmpegAudioDecoder::DoFlush(const base::Closure& callback) { avcodec_flush_buffers(codec_context_); estimated_next_timestamp_ = kNoTimestamp; - - callback->Run(); - delete callback; + callback.Run(); } void FFmpegAudioDecoder::DoProduceAudioSamples( @@ -234,7 +230,7 @@ void FFmpegAudioDecoder::DoDecodeBuffer(const scoped_refptr<Buffer>& input) { } // Decoding finished successfully, update stats and execute callback. - stats_callback_->Run(statistics); + stats_callback_.Run(statistics); if (output) { DCHECK_GT(output_buffers_.size(), 0u); output_buffers_.pop_front(); @@ -259,7 +255,7 @@ void FFmpegAudioDecoder::DecodeBuffer(Buffer* buffer) { scoped_refptr<Buffer> ref_buffer(buffer); message_loop_->PostTask( FROM_HERE, - NewRunnableMethod(this, &FFmpegAudioDecoder::DoDecodeBuffer, ref_buffer)); + base::Bind(&FFmpegAudioDecoder::DoDecodeBuffer, this, ref_buffer)); } void FFmpegAudioDecoder::UpdateDurationAndTimestamp( diff --git a/media/filters/ffmpeg_audio_decoder.h b/media/filters/ffmpeg_audio_decoder.h index 65f499b..f961f40 100644 --- a/media/filters/ffmpeg_audio_decoder.h +++ b/media/filters/ffmpeg_audio_decoder.h @@ -22,11 +22,11 @@ class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { virtual ~FFmpegAudioDecoder(); // Filter implementation. - virtual void Flush(FilterCallback* callback) OVERRIDE; + virtual void Flush(const base::Closure& callback) OVERRIDE; // AudioDecoder implementation. - virtual void Initialize(DemuxerStream* stream, FilterCallback* callback, - StatisticsCallback* stats_callback) OVERRIDE; + virtual void Initialize(DemuxerStream* stream, const base::Closure& callback, + const StatisticsCallback& stats_callback) OVERRIDE; virtual void ProduceAudioSamples(scoped_refptr<Buffer> output) OVERRIDE; virtual int bits_per_channel() OVERRIDE; virtual ChannelLayout channel_layout() OVERRIDE; @@ -35,9 +35,9 @@ class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { private: // Methods running on decoder thread. void DoInitialize(const scoped_refptr<DemuxerStream>& stream, - FilterCallback* callback, - StatisticsCallback* stats_callback); - void DoFlush(FilterCallback* callback); + const base::Closure& callback, + const StatisticsCallback& stats_callback); + void DoFlush(const base::Closure& callback); void DoProduceAudioSamples(const scoped_refptr<Buffer>& output); void DoDecodeBuffer(const scoped_refptr<Buffer>& input); @@ -56,7 +56,7 @@ class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { MessageLoop* message_loop_; scoped_refptr<DemuxerStream> demuxer_stream_; - scoped_ptr<StatisticsCallback> stats_callback_; + StatisticsCallback stats_callback_; AVCodecContext* codec_context_; // Decoded audio format. diff --git a/media/filters/ffmpeg_audio_decoder_unittest.cc b/media/filters/ffmpeg_audio_decoder_unittest.cc index d9919427..a365be9 100644 --- a/media/filters/ffmpeg_audio_decoder_unittest.cc +++ b/media/filters/ffmpeg_audio_decoder_unittest.cc @@ -74,8 +74,8 @@ class FFmpegAudioDecoderTest : public testing::Test { decoder_->Initialize(demuxer_, NewExpectedCallback(), - NewCallback(&statistics_callback_, - &MockStatisticsCallback::OnStatistics)); + base::Bind(&MockStatisticsCallback::OnStatistics, + base::Unretained(&statistics_callback_))); message_loop_.RunAllPending(); } diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc index 3d7bb12..56981e4 100644 --- a/media/filters/ffmpeg_demuxer.cc +++ b/media/filters/ffmpeg_demuxer.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" #include "base/callback.h" #include "base/command_line.h" #include "base/memory/scoped_ptr.h" @@ -166,8 +167,8 @@ void FFmpegDemuxerStream::Read(const ReadCallback& read_callback) { demuxer_->PostDemuxTask(); } else { - demuxer_->message_loop()->PostTask(FROM_HERE, - NewRunnableMethod(this, &FFmpegDemuxerStream::ReadTask, read_callback)); + demuxer_->message_loop()->PostTask(FROM_HERE, base::Bind( + &FFmpegDemuxerStream::ReadTask, this, read_callback)); } } @@ -288,25 +289,21 @@ FFmpegDemuxer::~FFmpegDemuxer() { void FFmpegDemuxer::PostDemuxTask() { message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &FFmpegDemuxer::DemuxTask)); + base::Bind(&FFmpegDemuxer::DemuxTask, this)); } -void FFmpegDemuxer::Stop(FilterCallback* callback) { +void FFmpegDemuxer::Stop(const base::Closure& callback) { // Post a task to notify the streams to stop as well. message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &FFmpegDemuxer::StopTask, callback)); + base::Bind(&FFmpegDemuxer::StopTask, this, callback)); // Then wakes up the thread from reading. SignalReadCompleted(DataSource::kReadError); } void FFmpegDemuxer::Seek(base::TimeDelta time, const FilterStatusCB& cb) { - // TODO(hclam): by returning from this method, it is assumed that the seek - // operation is completed and filters behind the demuxer is good to issue - // more reads, but we are posting a task here, which makes the seek operation - // asynchronous, should change how seek works to make it fully asynchronous. message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &FFmpegDemuxer::SeekTask, time, cb)); + base::Bind(&FFmpegDemuxer::SeekTask, this, time, cb)); } void FFmpegDemuxer::SetPlaybackRate(float playback_rate) { @@ -321,7 +318,7 @@ void FFmpegDemuxer::SetPreload(Preload preload) { void FFmpegDemuxer::OnAudioRendererDisabled() { message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &FFmpegDemuxer::DisableAudioStreamTask)); + base::Bind(&FFmpegDemuxer::DisableAudioStreamTask, this)); } void FFmpegDemuxer::set_host(FilterHost* filter_host) { @@ -340,10 +337,9 @@ void FFmpegDemuxer::Initialize(DataSource* data_source, const PipelineStatusCB& callback) { message_loop_->PostTask( FROM_HERE, - NewRunnableMethod(this, - &FFmpegDemuxer::InitializeTask, - make_scoped_refptr(data_source), - callback)); + base::Bind(&FFmpegDemuxer::InitializeTask, this, + make_scoped_refptr(data_source), + callback)); } scoped_refptr<DemuxerStream> FFmpegDemuxer::GetStream( @@ -373,7 +369,7 @@ int FFmpegDemuxer::Read(int size, uint8* data) { // Asynchronous read from data source. data_source_->Read(read_position_, size, data, - NewCallback(this, &FFmpegDemuxer::OnReadCompleted)); + base::Bind(&FFmpegDemuxer::OnReadCompleted, this)); // TODO(hclam): The method is called on the demuxer thread and this method // call will block the thread. We need to implemented an additional thread to @@ -656,7 +652,7 @@ void FFmpegDemuxer::DemuxTask() { } } -void FFmpegDemuxer::StopTask(FilterCallback* callback) { +void FFmpegDemuxer::StopTask(const base::Closure& callback) { DCHECK_EQ(MessageLoop::current(), message_loop_); StreamVector::iterator iter; for (iter = streams_.begin(); iter != streams_.end(); ++iter) { @@ -666,8 +662,7 @@ void FFmpegDemuxer::StopTask(FilterCallback* callback) { if (data_source_) { data_source_->Stop(callback); } else { - callback->Run(); - delete callback; + callback.Run(); } } diff --git a/media/filters/ffmpeg_demuxer.h b/media/filters/ffmpeg_demuxer.h index e9bd127..2622111 100644 --- a/media/filters/ffmpeg_demuxer.h +++ b/media/filters/ffmpeg_demuxer.h @@ -138,7 +138,7 @@ class MEDIA_EXPORT FFmpegDemuxer : public Demuxer, public FFmpegURLProtocol { DataSource* data_source, const PipelineStatusCB& callback); // Demuxer implementation. - virtual void Stop(FilterCallback* callback) OVERRIDE; + virtual void Stop(const base::Closure& callback) OVERRIDE; virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb) OVERRIDE; virtual void OnAudioRendererDisabled() OVERRIDE; virtual void set_host(FilterHost* filter_host) OVERRIDE; @@ -181,7 +181,7 @@ class MEDIA_EXPORT FFmpegDemuxer : public Demuxer, public FFmpegURLProtocol { void DemuxTask(); // Carries out stopping the demuxer streams on the demuxer thread. - void StopTask(FilterCallback* callback); + void StopTask(const base::Closure& callback); // Carries out disabling the audio stream on the demuxer thread. void DisableAudioStreamTask(); diff --git a/media/filters/ffmpeg_demuxer_factory.cc b/media/filters/ffmpeg_demuxer_factory.cc index 65dbeb5..626cded 100644 --- a/media/filters/ffmpeg_demuxer_factory.cc +++ b/media/filters/ffmpeg_demuxer_factory.cc @@ -9,19 +9,6 @@ namespace media { -static void DemuxerInitDone(DemuxerFactory::BuildCallback* cb, - const scoped_refptr<FFmpegDemuxer>& demuxer, - PipelineStatus status) { - scoped_ptr<DemuxerFactory::BuildCallback> callback(cb); - if (status != PIPELINE_OK) { - callback->Run(status, static_cast<Demuxer*>(NULL)); - return; - } - - callback->Run(PIPELINE_OK, demuxer.get()); -} - - FFmpegDemuxerFactory::FFmpegDemuxerFactory( DataSourceFactory* data_source_factory, MessageLoop* loop) @@ -29,47 +16,36 @@ FFmpegDemuxerFactory::FFmpegDemuxerFactory( FFmpegDemuxerFactory::~FFmpegDemuxerFactory() {} -// This class is a one-off whose raison d'etre is the lack of -// currying functionality in base/callback_old.h's machinery. Once -// {DataSource,Demuxer}Factory::BuildCallback are migrated to the new -// base/callback.h machinery these should be removed and replaced -// with currying calls to base::Bind(). -class DemuxerCallbackAsDataSourceCallback - : public DataSourceFactory::BuildCallback { - public: - DemuxerCallbackAsDataSourceCallback(DemuxerFactory::BuildCallback* cb, - MessageLoop* loop) - : cb_(cb), loop_(loop) { - DCHECK(cb_.get() && loop_); +static void DemuxerInitDone(const DemuxerFactory::BuildCallback& cb, + const scoped_refptr<FFmpegDemuxer>& demuxer, + PipelineStatus status) { + if (status != PIPELINE_OK) { + cb.Run(status, NULL); + return; } + cb.Run(PIPELINE_OK, demuxer.get()); +} - virtual ~DemuxerCallbackAsDataSourceCallback() {} - - virtual void RunWithParams( - const Tuple2<PipelineStatus, DataSource*>& params) { - PipelineStatus status = params.a; - DataSource* data_source = params.b; - if (status != PIPELINE_OK) { - cb_->Run(status, static_cast<Demuxer*>(NULL)); - return; - } - DCHECK(data_source); - scoped_refptr<FFmpegDemuxer> demuxer = new FFmpegDemuxer(loop_); - demuxer->Initialize( - data_source, - base::Bind(&DemuxerInitDone, cb_.release(), demuxer)); +static void InitializeDemuxerBasedOnDataSourceStatus( + const DemuxerFactory::BuildCallback& cb, + MessageLoop* loop, + PipelineStatus status, DataSource* data_source) { + if (status != PIPELINE_OK) { + cb.Run(status, NULL); + return; } + DCHECK(data_source); + scoped_refptr<FFmpegDemuxer> demuxer = new FFmpegDemuxer(loop); + demuxer->Initialize( + data_source, + base::Bind(&DemuxerInitDone, cb, demuxer)); +} - private: - scoped_ptr<DemuxerFactory::BuildCallback> cb_; - MessageLoop* loop_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(DemuxerCallbackAsDataSourceCallback); -}; - -void FFmpegDemuxerFactory::Build(const std::string& url, BuildCallback* cb) { +void FFmpegDemuxerFactory::Build(const std::string& url, + const BuildCallback& cb) { data_source_factory_->Build( - url, new DemuxerCallbackAsDataSourceCallback(cb, loop_)); + url, + base::Bind(&InitializeDemuxerBasedOnDataSourceStatus, cb, loop_)); } DemuxerFactory* FFmpegDemuxerFactory::Clone() const { diff --git a/media/filters/ffmpeg_demuxer_factory.h b/media/filters/ffmpeg_demuxer_factory.h index 37a5f43..8921531 100644 --- a/media/filters/ffmpeg_demuxer_factory.h +++ b/media/filters/ffmpeg_demuxer_factory.h @@ -23,8 +23,8 @@ class MEDIA_EXPORT FFmpegDemuxerFactory : public DemuxerFactory { virtual ~FFmpegDemuxerFactory(); // DemuxerFactory methods. - virtual void Build(const std::string& url, BuildCallback* cb); - virtual DemuxerFactory* Clone() const; + virtual void Build(const std::string& url, const BuildCallback& cb) OVERRIDE; + virtual DemuxerFactory* Clone() const OVERRIDE; private: scoped_ptr<DataSourceFactory> data_source_factory_; diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc index d5c76ae..34e3802 100644 --- a/media/filters/ffmpeg_demuxer_unittest.cc +++ b/media/filters/ffmpeg_demuxer_unittest.cc @@ -459,17 +459,16 @@ class MockFFmpegDemuxer : public FFmpegDemuxer { }; // A gmock helper method to execute the callback and deletes it. -void RunCallback(size_t size, DataSource::ReadCallback* callback) { - DCHECK(callback); - callback->RunWithParams(Tuple1<size_t>(size)); - delete callback; +void RunCallback(size_t size, const DataSource::ReadCallback& callback) { + DCHECK(!callback.is_null()); + callback.Run(size); } TEST_F(FFmpegDemuxerTest, ProtocolRead) { scoped_refptr<StrictMock<MockDataSource> > data_source = new StrictMock<MockDataSource>(); - EXPECT_CALL(*data_source, Stop(NotNull())) + EXPECT_CALL(*data_source, Stop(_)) .WillRepeatedly(Invoke(&RunStopFilterCallback)); // Creates a demuxer. @@ -484,7 +483,7 @@ TEST_F(FFmpegDemuxerTest, ProtocolRead) { // Actions taken in the first read. EXPECT_CALL(*data_source, GetSize(_)) .WillOnce(DoAll(SetArgPointee<0>(1024), Return(true))); - EXPECT_CALL(*data_source, Read(0, 512, kBuffer, NotNull())) + EXPECT_CALL(*data_source, Read(0, 512, kBuffer, _)) .WillOnce(WithArgs<1, 3>(Invoke(&RunCallback))); EXPECT_CALL(*demuxer, SignalReadCompleted(512)); EXPECT_CALL(*demuxer, WaitForRead()) @@ -494,7 +493,7 @@ TEST_F(FFmpegDemuxerTest, ProtocolRead) { // Second read. EXPECT_CALL(*data_source, GetSize(_)) .WillOnce(DoAll(SetArgPointee<0>(1024), Return(true))); - EXPECT_CALL(*data_source, Read(512, 512, kBuffer, NotNull())) + EXPECT_CALL(*data_source, Read(512, 512, kBuffer, _)) .WillOnce(WithArgs<1, 3>(Invoke(&RunCallback))); EXPECT_CALL(*demuxer, SignalReadCompleted(512)); EXPECT_CALL(*demuxer, WaitForRead()) diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc index 61a8771..a7785ec 100644 --- a/media/filters/ffmpeg_video_decoder.cc +++ b/media/filters/ffmpeg_video_decoder.cc @@ -7,9 +7,9 @@ #include <deque> #include "base/bind.h" +#include "base/callback.h" #include "base/message_loop.h" #include "base/task.h" -#include "media/base/callback.h" #include "media/base/demuxer_stream.h" #include "media/base/filters.h" #include "media/base/filter_host.h" @@ -34,33 +34,30 @@ FFmpegVideoDecoder::FFmpegVideoDecoder(MessageLoop* message_loop, FFmpegVideoDecoder::~FFmpegVideoDecoder() {} void FFmpegVideoDecoder::Initialize(DemuxerStream* demuxer_stream, - FilterCallback* callback, - StatisticsCallback* stats_callback) { + const base::Closure& callback, + const StatisticsCallback& stats_callback) { if (MessageLoop::current() != message_loop_) { message_loop_->PostTask( FROM_HERE, - NewRunnableMethod(this, - &FFmpegVideoDecoder::Initialize, - make_scoped_refptr(demuxer_stream), - callback, stats_callback)); + base::Bind(&FFmpegVideoDecoder::Initialize, this, + make_scoped_refptr(demuxer_stream), + callback, stats_callback)); return; } DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK(!demuxer_stream_); - DCHECK(!initialize_callback_.get()); + DCHECK(initialize_callback_.is_null()); if (!demuxer_stream) { host()->SetError(PIPELINE_ERROR_DECODE); - callback->Run(); - delete callback; - delete stats_callback; + callback.Run(); return; } demuxer_stream_ = demuxer_stream; - initialize_callback_.reset(callback); - statistics_callback_.reset(stats_callback); + initialize_callback_ = callback; + statistics_callback_ = stats_callback; AVStream* av_stream = demuxer_stream->GetAVStream(); if (!av_stream) { @@ -100,31 +97,28 @@ void FFmpegVideoDecoder::Initialize(DemuxerStream* demuxer_stream, void FFmpegVideoDecoder::OnInitializeComplete(const VideoCodecInfo& info) { DCHECK_EQ(MessageLoop::current(), message_loop_); - DCHECK(initialize_callback_.get()); + DCHECK(!initialize_callback_.is_null()); info_ = info; - AutoCallbackRunner done_runner(initialize_callback_.release()); - if (info.success) { state_ = kNormal; } else { host()->SetError(PIPELINE_ERROR_DECODE); } + ResetAndRunCB(&initialize_callback_); } -void FFmpegVideoDecoder::Stop(FilterCallback* callback) { +void FFmpegVideoDecoder::Stop(const base::Closure& callback) { if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &FFmpegVideoDecoder::Stop, - callback)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &FFmpegVideoDecoder::Stop, this, callback)); return; } DCHECK_EQ(MessageLoop::current(), message_loop_); - DCHECK(!uninitialize_callback_.get()); + DCHECK(uninitialize_callback_.is_null()); - uninitialize_callback_.reset(callback); + uninitialize_callback_ = callback; if (state_ != kUnInitialized) decode_engine_->Uninitialize(); else @@ -133,65 +127,60 @@ void FFmpegVideoDecoder::Stop(FilterCallback* callback) { void FFmpegVideoDecoder::OnUninitializeComplete() { DCHECK_EQ(MessageLoop::current(), message_loop_); - DCHECK(uninitialize_callback_.get()); + DCHECK(!uninitialize_callback_.is_null()); - AutoCallbackRunner done_runner(uninitialize_callback_.release()); state_ = kStopped; - // TODO(jiesun): Destroy the decoder context. + ResetAndRunCB(&uninitialize_callback_); } -void FFmpegVideoDecoder::Pause(FilterCallback* callback) { +void FFmpegVideoDecoder::Pause(const base::Closure& callback) { if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &FFmpegVideoDecoder::Pause, - callback)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &FFmpegVideoDecoder::Pause, this, callback)); return; } - AutoCallbackRunner done_runner(callback); state_ = kPausing; + callback.Run(); } -void FFmpegVideoDecoder::Flush(FilterCallback* callback) { +void FFmpegVideoDecoder::Flush(const base::Closure& callback) { if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &FFmpegVideoDecoder::Flush, - callback)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &FFmpegVideoDecoder::Flush, this, callback)); return; } DCHECK_EQ(MessageLoop::current(), message_loop_); - DCHECK(!flush_callback_.get()); + DCHECK(flush_callback_.is_null()); state_ = kFlushing; FlushBuffers(); - flush_callback_.reset(callback); + flush_callback_ = callback; decode_engine_->Flush(); } void FFmpegVideoDecoder::OnFlushComplete() { DCHECK_EQ(MessageLoop::current(), message_loop_); - DCHECK(flush_callback_.get()); - - AutoCallbackRunner done_runner(flush_callback_.release()); + DCHECK(!flush_callback_.is_null()); // Everything in the presentation time queue is invalid, clear the queue. pts_stream_.Flush(); // Mark flush operation had been done. state_ = kNormal; + + ResetAndRunCB(&flush_callback_); } void FFmpegVideoDecoder::Seek(base::TimeDelta time, const FilterStatusCB& cb) { if (MessageLoop::current() != message_loop_) { message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &FFmpegVideoDecoder::Seek, + base::Bind(&FFmpegVideoDecoder::Seek, this, time, cb)); return; } @@ -217,11 +206,8 @@ void FFmpegVideoDecoder::OnError() { void FFmpegVideoDecoder::OnReadComplete(Buffer* buffer_in) { scoped_refptr<Buffer> buffer(buffer_in); - message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, - &FFmpegVideoDecoder::OnReadCompleteTask, - buffer)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &FFmpegVideoDecoder::OnReadCompleteTask, this, buffer)); } void FFmpegVideoDecoder::OnReadCompleteTask(scoped_refptr<Buffer> buffer) { @@ -275,10 +261,8 @@ void FFmpegVideoDecoder::OnReadCompleteTask(scoped_refptr<Buffer> buffer) { void FFmpegVideoDecoder::ProduceVideoFrame( scoped_refptr<VideoFrame> video_frame) { if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, - &FFmpegVideoDecoder::ProduceVideoFrame, video_frame)); + message_loop_->PostTask(FROM_HERE, base::Bind( + &FFmpegVideoDecoder::ProduceVideoFrame, this, video_frame)); return; } @@ -305,7 +289,7 @@ void FFmpegVideoDecoder::ConsumeVideoFrame( DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK_NE(state_, kStopped); - statistics_callback_->Run(statistics); + statistics_callback_.Run(statistics); if (video_frame.get()) { if (kPausing == state_ || kFlushing == state_) { diff --git a/media/filters/ffmpeg_video_decoder.h b/media/filters/ffmpeg_video_decoder.h index a09ab5d..bc2b532 100644 --- a/media/filters/ffmpeg_video_decoder.h +++ b/media/filters/ffmpeg_video_decoder.h @@ -27,15 +27,15 @@ class MEDIA_EXPORT FFmpegVideoDecoder virtual ~FFmpegVideoDecoder(); // Filter implementation. - virtual void Stop(FilterCallback* callback) OVERRIDE; + virtual void Stop(const base::Closure& callback) OVERRIDE; virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb) OVERRIDE; - virtual void Pause(FilterCallback* callback) OVERRIDE; - virtual void Flush(FilterCallback* callback) OVERRIDE; + virtual void Pause(const base::Closure& callback) OVERRIDE; + virtual void Flush(const base::Closure& callback) OVERRIDE; // Decoder implementation. virtual void Initialize(DemuxerStream* demuxer_stream, - FilterCallback* callback, - StatisticsCallback* stats_callback) OVERRIDE; + const base::Closure& callback, + const StatisticsCallback& stats_callback) OVERRIDE; virtual void ProduceVideoFrame( scoped_refptr<VideoFrame> video_frame) OVERRIDE; virtual gfx::Size natural_size() OVERRIDE; @@ -74,8 +74,8 @@ class MEDIA_EXPORT FFmpegVideoDecoder kStopped }; - void OnFlushComplete(FilterCallback* callback); - void OnSeekComplete(FilterCallback* callback); + void OnFlushComplete(const base::Closure& callback); + void OnSeekComplete(const base::Closure& callback); void OnReadComplete(Buffer* buffer); // TODO(jiesun): until demuxer pass scoped_refptr<Buffer>: we could not merge @@ -96,11 +96,11 @@ class MEDIA_EXPORT FFmpegVideoDecoder scoped_ptr<VideoDecodeEngine> decode_engine_; scoped_ptr<VideoDecodeContext> decode_context_; - scoped_ptr<FilterCallback> initialize_callback_; - scoped_ptr<FilterCallback> uninitialize_callback_; - scoped_ptr<FilterCallback> flush_callback_; + base::Closure initialize_callback_; + base::Closure uninitialize_callback_; + base::Closure flush_callback_; FilterStatusCB seek_cb_; - scoped_ptr<StatisticsCallback> statistics_callback_; + StatisticsCallback statistics_callback_; // Hold video frames when flush happens. std::deque<scoped_refptr<VideoFrame> > frame_queue_flushed_; diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc index e5b9eeb..8938fd3 100644 --- a/media/filters/ffmpeg_video_decoder_unittest.cc +++ b/media/filters/ffmpeg_video_decoder_unittest.cc @@ -187,9 +187,9 @@ class FFmpegVideoDecoderTest : public testing::Test { message_loop_.RunAllPending(); } - StatisticsCallback* NewStatisticsCallback() { - return NewCallback(&stats_callback_object_, - &MockStatisticsCallback::OnStatistics); + StatisticsCallback NewStatisticsCallback() { + return base::Bind(&MockStatisticsCallback::OnStatistics, + base::Unretained(&stats_callback_object_)); } // Fixture members. diff --git a/media/filters/file_data_source.cc b/media/filters/file_data_source.cc index 40b76e6..9116b50 100644 --- a/media/filters/file_data_source.cc +++ b/media/filters/file_data_source.cc @@ -61,49 +61,43 @@ void FileDataSource::UpdateHostBytes() { } } -void FileDataSource::Stop(FilterCallback* callback) { +void FileDataSource::Stop(const base::Closure& callback) { base::AutoLock l(lock_); if (file_) { file_util::CloseFile(file_); file_ = NULL; file_size_ = 0; } - if (callback) { - callback->Run(); - delete callback; - } + if (!callback.is_null()) + callback.Run(); } void FileDataSource::Read(int64 position, size_t size, uint8* data, - ReadCallback* read_callback) { + const DataSource::ReadCallback& read_callback) { DCHECK(file_); base::AutoLock l(lock_); - scoped_ptr<ReadCallback> callback(read_callback); if (file_) { #if defined(OS_WIN) if (_fseeki64(file_, position, SEEK_SET)) { - callback->RunWithParams( - Tuple1<size_t>(static_cast<size_t>(DataSource::kReadError))); + read_callback.Run(DataSource::kReadError); return; } #else CHECK(position <= std::numeric_limits<int32>::max()); // TODO(hclam): Change fseek() to support 64-bit position. if (fseek(file_, static_cast<int32>(position), SEEK_SET)) { - callback->RunWithParams( - Tuple1<size_t>(static_cast<size_t>(DataSource::kReadError))); + read_callback.Run(DataSource::kReadError); return; } #endif size_t size_read = fread(data, 1, size, file_); if (size_read == size || !ferror(file_)) { - callback->RunWithParams( - Tuple1<size_t>(static_cast<size_t>(size_read))); + read_callback.Run(size_read); return; } } - callback->RunWithParams(Tuple1<size_t>(static_cast<size_t>(kReadError))); + read_callback.Run(kReadError); } bool FileDataSource::GetSize(int64* size_out) { diff --git a/media/filters/file_data_source.h b/media/filters/file_data_source.h index 134bec1..fb905d2 100644 --- a/media/filters/file_data_source.h +++ b/media/filters/file_data_source.h @@ -25,11 +25,11 @@ class MEDIA_EXPORT FileDataSource : public DataSource { // Implementation of Filter. virtual void set_host(FilterHost* filter_host); - virtual void Stop(FilterCallback* callback); + virtual void Stop(const base::Closure& callback); // Implementation of DataSource. virtual void Read(int64 position, size_t size, uint8* data, - ReadCallback* read_callback); + const DataSource::ReadCallback& read_callback); virtual bool GetSize(int64* size_out); virtual bool IsStreaming(); virtual void SetPreload(Preload preload); diff --git a/media/filters/file_data_source_factory.cc b/media/filters/file_data_source_factory.cc index 823fa01..a2109a9 100644 --- a/media/filters/file_data_source_factory.cc +++ b/media/filters/file_data_source_factory.cc @@ -14,13 +14,12 @@ FileDataSourceFactory::FileDataSourceFactory() {} FileDataSourceFactory::~FileDataSourceFactory() {} void FileDataSourceFactory::Build(const std::string& url, - BuildCallback* callback) { - DCHECK(callback); + const BuildCallback& callback) { + DCHECK(!callback.is_null()); if (url.empty()) { - callback->Run(media::PIPELINE_ERROR_URL_NOT_FOUND, - static_cast<media::DataSource*>(NULL)); - delete callback; + callback.Run(media::PIPELINE_ERROR_URL_NOT_FOUND, + static_cast<media::DataSource*>(NULL)); return; } @@ -29,8 +28,7 @@ void FileDataSourceFactory::Build(const std::string& url, PipelineStatus status = file_data_source->Initialize(url); DataSource* data_source = (status == PIPELINE_OK) ? file_data_source.get() : NULL; - callback->Run(status, data_source); - delete callback; + callback.Run(status, data_source); } DataSourceFactory* FileDataSourceFactory::Clone() const { diff --git a/media/filters/file_data_source_factory.h b/media/filters/file_data_source_factory.h index 94b056c..a5ed0c5 100644 --- a/media/filters/file_data_source_factory.h +++ b/media/filters/file_data_source_factory.h @@ -15,7 +15,7 @@ class MEDIA_EXPORT FileDataSourceFactory : public DataSourceFactory { virtual ~FileDataSourceFactory(); // DataSourceFactory methods. - virtual void Build(const std::string& url, BuildCallback* callback); + virtual void Build(const std::string& url, const BuildCallback& callback); virtual DataSourceFactory* Clone() const; private: diff --git a/media/filters/file_data_source_unittest.cc b/media/filters/file_data_source_unittest.cc index 5cf012b..ee4dfc0 100644 --- a/media/filters/file_data_source_unittest.cc +++ b/media/filters/file_data_source_unittest.cc @@ -5,6 +5,7 @@ #include <string> #include "base/base_paths.h" +#include "base/bind.h" #include "base/file_path.h" #include "base/path_service.h" #include "base/utf_string_conversions.h" @@ -78,19 +79,19 @@ TEST(FileDataSourceTest, ReadData) { ReadCallbackHandler handler; EXPECT_CALL(handler, ReadCallback(10)); - filter->Read(0, 10, ten_bytes, - NewCallback(&handler, &ReadCallbackHandler::ReadCallback)); + filter->Read(0, 10, ten_bytes, base::Bind( + &ReadCallbackHandler::ReadCallback, base::Unretained(&handler))); EXPECT_EQ('0', ten_bytes[0]); EXPECT_EQ('5', ten_bytes[5]); EXPECT_EQ('9', ten_bytes[9]); EXPECT_CALL(handler, ReadCallback(0)); - filter->Read(10, 10, ten_bytes, - NewCallback(&handler, &ReadCallbackHandler::ReadCallback)); + filter->Read(10, 10, ten_bytes, base::Bind( + &ReadCallbackHandler::ReadCallback, base::Unretained(&handler))); EXPECT_CALL(handler, ReadCallback(5)); - filter->Read(5, 10, ten_bytes, - NewCallback(&handler, &ReadCallbackHandler::ReadCallback)); + filter->Read(5, 10, ten_bytes, base::Bind( + &ReadCallbackHandler::ReadCallback, base::Unretained(&handler))); EXPECT_EQ('5', ten_bytes[0]); filter->Stop(NewExpectedCallback()); diff --git a/media/filters/null_video_renderer.cc b/media/filters/null_video_renderer.cc index dc6e5de..2c81ded 100644 --- a/media/filters/null_video_renderer.cc +++ b/media/filters/null_video_renderer.cc @@ -13,9 +13,8 @@ bool NullVideoRenderer::OnInitialize(media::VideoDecoder* decoder) { return true; } -void NullVideoRenderer::OnStop(media::FilterCallback* callback) { - callback->Run(); - delete callback; +void NullVideoRenderer::OnStop(const base::Closure& callback) { + callback.Run(); } void NullVideoRenderer::OnFrameAvailable() { diff --git a/media/filters/null_video_renderer.h b/media/filters/null_video_renderer.h index 05bf26a..e3c3a6c 100644 --- a/media/filters/null_video_renderer.h +++ b/media/filters/null_video_renderer.h @@ -15,7 +15,7 @@ class NullVideoRenderer : public VideoRendererBase { // VideoRendererBase implementation. virtual bool OnInitialize(VideoDecoder* decoder); - virtual void OnStop(FilterCallback* callback); + virtual void OnStop(const base::Closure& callback); virtual void OnFrameAvailable(); private: diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc index c7d37811..ee95161 100644 --- a/media/filters/video_renderer_base.cc +++ b/media/filters/video_renderer_base.cc @@ -6,7 +6,6 @@ #include "base/callback.h" #include "base/threading/platform_thread.h" #include "media/base/buffers.h" -#include "media/base/callback.h" #include "media/base/filter_host.h" #include "media/base/limits.h" #include "media/base/video_frame.h" @@ -42,32 +41,31 @@ VideoRendererBase::~VideoRendererBase() { DCHECK(state_ == kUninitialized || state_ == kStopped); } -void VideoRendererBase::Play(FilterCallback* callback) { +void VideoRendererBase::Play(const base::Closure& callback) { base::AutoLock auto_lock(lock_); DCHECK_EQ(kPrerolled, state_); - scoped_ptr<FilterCallback> c(callback); state_ = kPlaying; - callback->Run(); + callback.Run(); } -void VideoRendererBase::Pause(FilterCallback* callback) { +void VideoRendererBase::Pause(const base::Closure& callback) { base::AutoLock auto_lock(lock_); DCHECK(state_ != kUninitialized || state_ == kError); - AutoCallbackRunner done_runner(callback); state_ = kPaused; + callback.Run(); } -void VideoRendererBase::Flush(FilterCallback* callback) { +void VideoRendererBase::Flush(const base::Closure& callback) { base::AutoLock auto_lock(lock_); DCHECK_EQ(state_, kPaused); - flush_callback_.reset(callback); + flush_callback_ = callback; state_ = kFlushing; if (!pending_paint_) FlushBuffers_Locked(); } -void VideoRendererBase::Stop(FilterCallback* callback) { +void VideoRendererBase::Stop(const base::Closure& callback) { base::PlatformThreadHandle old_thread_handle = base::kNullThreadHandle; { base::AutoLock auto_lock(lock_); @@ -131,17 +129,16 @@ void VideoRendererBase::Seek(base::TimeDelta time, const FilterStatusCB& cb) { } void VideoRendererBase::Initialize(VideoDecoder* decoder, - FilterCallback* callback, - StatisticsCallback* stats_callback) { + const base::Closure& callback, + const StatisticsCallback& stats_callback) { base::AutoLock auto_lock(lock_); DCHECK(decoder); - DCHECK(callback); - DCHECK(stats_callback); + DCHECK(!callback.is_null()); + DCHECK(!stats_callback.is_null()); DCHECK_EQ(kUninitialized, state_); decoder_ = decoder; - AutoCallbackRunner done_runner(callback); - statistics_callback_.reset(stats_callback); + statistics_callback_ = stats_callback; decoder_->set_consume_video_frame_callback( base::Bind(&VideoRendererBase::ConsumeVideoFrame, @@ -155,6 +152,7 @@ void VideoRendererBase::Initialize(VideoDecoder* decoder, // we're holding the lock? if (!OnInitialize(decoder)) { EnterErrorState_Locked(PIPELINE_ERROR_INITIALIZATION_FAILED); + callback.Run(); return; } @@ -168,6 +166,7 @@ void VideoRendererBase::Initialize(VideoDecoder* decoder, if (!base::PlatformThread::Create(0, this, &thread_)) { NOTREACHED() << "Video thread creation failed"; EnterErrorState_Locked(PIPELINE_ERROR_INITIALIZATION_FAILED); + callback.Run(); return; } @@ -176,7 +175,7 @@ void VideoRendererBase::Initialize(VideoDecoder* decoder, // TODO(scherkus): find out if this is necessary, but it seems to help. ::SetThreadPriority(thread_, THREAD_PRIORITY_ABOVE_NORMAL); #endif // defined(OS_WIN) - + callback.Run(); } bool VideoRendererBase::HasEnded() { @@ -195,7 +194,7 @@ void VideoRendererBase::ThreadMain() { if (frames_dropped > 0) { PipelineStatistics statistics; statistics.video_frames_dropped = frames_dropped; - statistics_callback_->Run(statistics); + statistics_callback_.Run(statistics); frames_dropped = 0; } @@ -368,7 +367,7 @@ void VideoRendererBase::ConsumeVideoFrame(scoped_refptr<VideoFrame> frame) { if (frame) { PipelineStatistics statistics; statistics.video_frames_decoded = 1; - statistics_callback_->Run(statistics); + statistics_callback_.Run(statistics); } base::AutoLock auto_lock(lock_); @@ -507,10 +506,9 @@ void VideoRendererBase::OnFlushDone_Locked() { DCHECK(!current_frame_.get()); DCHECK(frames_queue_ready_.empty()); - if (flush_callback_.get()) { // This ensures callback is invoked once. - flush_callback_->Run(); - flush_callback_.reset(); - } + if (!flush_callback_.is_null()) // This ensures callback is invoked once. + ResetAndRunCB(&flush_callback_); + state_ = kFlushed; } @@ -546,7 +544,7 @@ base::TimeDelta VideoRendererBase::CalculateSleepDuration( void VideoRendererBase::EnterErrorState_Locked(PipelineStatus status) { lock_.AssertAcquired(); - scoped_ptr<FilterCallback> callback; + base::Closure callback; State old_state = state_; state_ = kError; @@ -565,8 +563,8 @@ void VideoRendererBase::EnterErrorState_Locked(PipelineStatus status) { break; case kFlushing: - CHECK(flush_callback_.get()); - callback.swap(flush_callback_); + CHECK(!flush_callback_.is_null()); + std::swap(callback, flush_callback_); break; case kSeeking: @@ -585,8 +583,8 @@ void VideoRendererBase::EnterErrorState_Locked(PipelineStatus status) { host()->SetError(status); - if (callback.get()) - callback->Run(); + if (!callback.is_null()) + callback.Run(); } void VideoRendererBase::DoStopOrErrorFlush_Locked() { diff --git a/media/filters/video_renderer_base.h b/media/filters/video_renderer_base.h index dcecd45..2125e45 100644 --- a/media/filters/video_renderer_base.h +++ b/media/filters/video_renderer_base.h @@ -37,17 +37,17 @@ class MEDIA_EXPORT VideoRendererBase virtual ~VideoRendererBase(); // Filter implementation. - virtual void Play(FilterCallback* callback); - virtual void Pause(FilterCallback* callback); - virtual void Flush(FilterCallback* callback); - virtual void Stop(FilterCallback* callback); + virtual void Play(const base::Closure& callback); + virtual void Pause(const base::Closure& callback); + virtual void Flush(const base::Closure& callback); + virtual void Stop(const base::Closure& callback); virtual void SetPlaybackRate(float playback_rate); virtual void Seek(base::TimeDelta time, const FilterStatusCB& cb); // VideoRenderer implementation. virtual void Initialize(VideoDecoder* decoder, - FilterCallback* callback, - StatisticsCallback* stats_callback); + const base::Closure& callback, + const StatisticsCallback& stats_callback); virtual bool HasEnded(); // PlatformThread::Delegate implementation. @@ -74,7 +74,7 @@ class MEDIA_EXPORT VideoRendererBase // // Implementors should perform any necessary cleanup before calling the // callback. - virtual void OnStop(FilterCallback* callback) = 0; + virtual void OnStop(const base::Closure& callback) = 0; // Subclass interface. Called when a new frame is ready for display, which // can be accessed via GetCurrentFrame(). @@ -194,9 +194,9 @@ class MEDIA_EXPORT VideoRendererBase float playback_rate_; // Filter callbacks. - scoped_ptr<FilterCallback> flush_callback_; + base::Closure flush_callback_; FilterStatusCB seek_cb_; - scoped_ptr<StatisticsCallback> statistics_callback_; + StatisticsCallback statistics_callback_; base::TimeDelta seek_timestamp_; diff --git a/media/filters/video_renderer_base_unittest.cc b/media/filters/video_renderer_base_unittest.cc index b43c805..71db8e2 100644 --- a/media/filters/video_renderer_base_unittest.cc +++ b/media/filters/video_renderer_base_unittest.cc @@ -3,8 +3,8 @@ // found in the LICENSE file. #include "base/bind.h" +#include "base/callback.h" #include "base/stl_util.h" -#include "media/base/callback.h" #include "media/base/data_buffer.h" #include "media/base/limits.h" #include "media/base/mock_callback.h" @@ -25,7 +25,7 @@ using ::testing::StrictMock; namespace media { ACTION(OnStop) { - AutoCallbackRunner auto_runner(arg0); + arg0.Run(); } // Mocked subclass of VideoRendererBase for testing purposes. @@ -36,7 +36,7 @@ class MockVideoRendererBase : public VideoRendererBase { // VideoRendererBase implementation. MOCK_METHOD1(OnInitialize, bool(VideoDecoder* decoder)); - MOCK_METHOD1(OnStop, void(FilterCallback* callback)); + MOCK_METHOD1(OnStop, void(const base::Closure& callback)); MOCK_METHOD0(OnFrameAvailable, void()); // Used for verifying check points during tests. @@ -69,7 +69,7 @@ class VideoRendererBaseTest : public ::testing::Test { if (renderer_.get()) { // Expect a call into the subclass. - EXPECT_CALL(*renderer_, OnStop(NotNull())) + EXPECT_CALL(*renderer_, OnStop(_)) .WillOnce(DoAll(OnStop(), Return())) .RetiresOnSaturation(); @@ -165,9 +165,9 @@ class VideoRendererBaseTest : public ::testing::Test { static const gfx::Size kNaturalSize; static const int64 kDuration; - StatisticsCallback* NewStatisticsCallback() { - return NewCallback(&stats_callback_object_, - &MockStatisticsCallback::OnStatistics); + StatisticsCallback NewStatisticsCallback() { + return base::Bind(&MockStatisticsCallback::OnStatistics, + base::Unretained(&stats_callback_object_)); } // Fixture members. @@ -314,7 +314,7 @@ TEST_F(VideoRendererBaseTest, Error_DuringPaint) { TEST_F(VideoRendererBaseTest, GetCurrentFrame_AfterStop) { Initialize(); - EXPECT_CALL(*renderer_, OnStop(NotNull())) + EXPECT_CALL(*renderer_, OnStop(_)) .WillOnce(DoAll(OnStop(), Return())) .RetiresOnSaturation(); diff --git a/media/media.gyp b/media/media.gyp index 4844727..7e3d01b 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -89,8 +89,6 @@ 'base/bitstream_buffer.h', 'base/buffers.cc', 'base/buffers.h', - 'base/callback.cc', - 'base/callback.h', 'base/channel_layout.cc', 'base/channel_layout.h', 'base/clock.cc', @@ -732,28 +730,31 @@ }, }, }, - { - 'target_name': 'mfdecoder', - 'type': 'executable', - 'dependencies': [ - 'media', - 'yuv_convert', - '../base/base.gyp:base', - ], - 'include_dirs': [ - '..', - ], - 'sources': [ - 'tools/mfdecoder/main.cc', - 'tools/mfdecoder/mfdecoder.h', - 'tools/mfdecoder/mfdecoder.cc', - ], - 'msvs_settings': { - 'VCLinkerTool': { - 'SubSystem': '1', # Set /SUBSYSTEM:CONSOLE - }, - }, - }, + # TODO(fischman): this target doesn't build w/ the new base::Bind + # world (media/tools/mfdecoder/main.cc:412). Figure out how to fix it + # (see bug 94995) or delete the target & source files if no longer used. + # { + # 'target_name': 'mfdecoder', + # 'type': 'executable', + # 'dependencies': [ + # 'media', + # 'yuv_convert', + # '../base/base.gyp:base', + # ], + # 'include_dirs': [ + # '..', + # ], + # 'sources': [ + # 'tools/mfdecoder/main.cc', + # 'tools/mfdecoder/mfdecoder.h', + # 'tools/mfdecoder/mfdecoder.cc', + # ], + # 'msvs_settings': { + # 'VCLinkerTool': { + # 'SubSystem': '1', # Set /SUBSYSTEM:CONSOLE + # }, + # }, + # }, ], }], ['OS!="mac"', { diff --git a/media/tools/mfdecoder/main.cc b/media/tools/mfdecoder/main.cc index 4d35f9d..79ea707 100644 --- a/media/tools/mfdecoder/main.cc +++ b/media/tools/mfdecoder/main.cc @@ -17,6 +17,7 @@ #include "base/at_exit.h" #include "base/basictypes.h" +#include "base/bind.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" @@ -407,12 +408,14 @@ static void RepaintTask(media::MFDecoder* decoder, HWND video_window, int64 delta = (end-start).InMilliseconds(); MessageLoopForUI::current()->PostDelayedTask( FROM_HERE, - NewRunnableFunction(&RepaintTask, decoder, video_window, device), - std::max<int64>(0L, 30-delta)); + base::Bind(&RepaintTask, base::Unretained(decoder), + video_window, device), + std::max<int64>(0L, 30-delta)); } else { MessageLoopForUI::current()->PostTask( FROM_HERE, - NewRunnableFunction(&RepaintTask, decoder, video_window, device)); + base::Bind(&RepaintTask, base::Unretained(decoder), + video_window, device)); } } } @@ -532,11 +535,9 @@ int main(int argc, char** argv) { MessageLoopForUI message_loop; // The device is NULL if DXVA2 is not enabled. - MessageLoopForUI::current()->PostTask(FROM_HERE, - NewRunnableFunction(&RepaintTask, - decoder.get(), - video_window, - device.get())); + MessageLoopForUI::current()->PostTask(FROM_HERE, base::Bind( + &RepaintTask, base::Unretained(decoder.get()), + video_window, device.get())); MessageLoopForUI::current()->Run(NULL); printf("Decoding finished\n"); diff --git a/media/tools/player_wtl/wtl_renderer.cc b/media/tools/player_wtl/wtl_renderer.cc index c5d9fd3..9e1589f 100644 --- a/media/tools/player_wtl/wtl_renderer.cc +++ b/media/tools/player_wtl/wtl_renderer.cc @@ -18,11 +18,9 @@ bool WtlVideoRenderer::OnInitialize(media::VideoDecoder* decoder) { return true; } -void WtlVideoRenderer::OnStop(media::FilterCallback* callback) { - if (callback) { - callback->Run(); - delete callback; - } +void WtlVideoRenderer::OnStop(const base::Closure& callback) { + if (!callback.is_null()) + callback.Run(); } void WtlVideoRenderer::OnFrameAvailable() { diff --git a/media/tools/player_wtl/wtl_renderer.h b/media/tools/player_wtl/wtl_renderer.h index e929d8e..8e504b8 100644 --- a/media/tools/player_wtl/wtl_renderer.h +++ b/media/tools/player_wtl/wtl_renderer.h @@ -17,7 +17,7 @@ class WtlVideoRenderer : public media::VideoRendererBase { protected: // VideoRendererBase implementation. virtual bool OnInitialize(media::VideoDecoder* decoder); - virtual void OnStop(media::FilterCallback* callback); + virtual void OnStop(const base::Closure& callback); virtual void OnFrameAvailable(); private: diff --git a/media/tools/player_x11/gl_video_renderer.cc b/media/tools/player_x11/gl_video_renderer.cc index 6c6cda4..3ce1f5f 100644 --- a/media/tools/player_x11/gl_video_renderer.cc +++ b/media/tools/player_x11/gl_video_renderer.cc @@ -6,6 +6,7 @@ #include <X11/Xutil.h> +#include "base/bind.h" #include "base/message_loop.h" #include "media/base/buffers.h" #include "media/base/video_frame.h" @@ -22,13 +23,11 @@ GlVideoRenderer::GlVideoRenderer(Display* display, Window window, GlVideoRenderer::~GlVideoRenderer() {} -void GlVideoRenderer::OnStop(media::FilterCallback* callback) { +void GlVideoRenderer::OnStop(const base::Closure& callback) { glXMakeCurrent(display_, 0, NULL); glXDestroyContext(display_, gl_context_); - if (callback) { - callback->Run(); - delete callback; - } + if (!callback.is_null()) + callback.Run(); } static GLXContext InitGLContext(Display* display, Window window) { @@ -231,7 +230,7 @@ bool GlVideoRenderer::OnInitialize(media::VideoDecoder* decoder) { void GlVideoRenderer::OnFrameAvailable() { main_message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &GlVideoRenderer::PaintOnMainThread)); + base::Bind(&GlVideoRenderer::PaintOnMainThread, this)); } void GlVideoRenderer::PaintOnMainThread() { diff --git a/media/tools/player_x11/gl_video_renderer.h b/media/tools/player_x11/gl_video_renderer.h index 9d816f7..bda881d 100644 --- a/media/tools/player_x11/gl_video_renderer.h +++ b/media/tools/player_x11/gl_video_renderer.h @@ -19,7 +19,7 @@ class GlVideoRenderer : public media::VideoRendererBase { protected: // VideoRendererBase implementation. virtual bool OnInitialize(media::VideoDecoder* decoder); - virtual void OnStop(media::FilterCallback* callback); + virtual void OnStop(const base::Closure& callback); virtual void OnFrameAvailable(); private: diff --git a/media/tools/player_x11/player_x11.cc b/media/tools/player_x11/player_x11.cc index 2434916..28b915b 100644 --- a/media/tools/player_x11/player_x11.cc +++ b/media/tools/player_x11/player_x11.cc @@ -14,7 +14,6 @@ #include "base/memory/scoped_ptr.h" #include "base/threading/platform_thread.h" #include "base/threading/thread.h" -#include "media/base/callback.h" #include "media/base/filter_collection.h" #include "media/base/media.h" #include "media/base/media_log.h" @@ -190,9 +189,9 @@ void PeriodicalUpdate( } } - message_loop->PostDelayedTask(FROM_HERE, - NewRunnableFunction(PeriodicalUpdate, make_scoped_refptr(pipeline), - message_loop, audio_only), 10); + message_loop->PostDelayedTask(FROM_HERE, base::Bind( + PeriodicalUpdate, make_scoped_refptr(pipeline), + message_loop, audio_only), 10); } int main(int argc, char** argv) { @@ -251,9 +250,8 @@ int main(int argc, char** argv) { // Check if video is present. audio_only = !pipeline->HasVideo(); - message_loop.PostTask(FROM_HERE, - NewRunnableFunction(PeriodicalUpdate, pipeline, - &message_loop, audio_only)); + message_loop.PostTask(FROM_HERE, base::Bind( + PeriodicalUpdate, pipeline, &message_loop, audio_only)); message_loop.Run(); } else{ std::cout << "Pipeline initialization failed..." << std::endl; diff --git a/media/tools/player_x11/x11_video_renderer.cc b/media/tools/player_x11/x11_video_renderer.cc index a06f6b8..70191ee 100644 --- a/media/tools/player_x11/x11_video_renderer.cc +++ b/media/tools/player_x11/x11_video_renderer.cc @@ -9,6 +9,7 @@ #include <X11/extensions/Xrender.h> #include <X11/extensions/Xcomposite.h> +#include "base/bind.h" #include "base/message_loop.h" #include "media/base/video_frame.h" #include "media/base/yuv_convert.h" @@ -79,15 +80,12 @@ X11VideoRenderer::X11VideoRenderer(Display* display, Window window, X11VideoRenderer::~X11VideoRenderer() {} -void X11VideoRenderer::OnStop(media::FilterCallback* callback) { - if (image_) { +void X11VideoRenderer::OnStop(const base::Closure& callback) { + if (image_) XDestroyImage(image_); - } XRenderFreePicture(display_, picture_); - if (callback) { - callback->Run(); - delete callback; - } + if (!callback.is_null()) + callback.Run(); } bool X11VideoRenderer::OnInitialize(media::VideoDecoder* decoder) { @@ -129,7 +127,7 @@ bool X11VideoRenderer::OnInitialize(media::VideoDecoder* decoder) { void X11VideoRenderer::OnFrameAvailable() { main_message_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &X11VideoRenderer::PaintOnMainThread)); + base::Bind(&X11VideoRenderer::PaintOnMainThread, this)); } void X11VideoRenderer::PaintOnMainThread() { diff --git a/media/tools/player_x11/x11_video_renderer.h b/media/tools/player_x11/x11_video_renderer.h index d208779..16640f4 100644 --- a/media/tools/player_x11/x11_video_renderer.h +++ b/media/tools/player_x11/x11_video_renderer.h @@ -20,7 +20,7 @@ class X11VideoRenderer : public media::VideoRendererBase { protected: // VideoRendererBase implementation. virtual bool OnInitialize(media::VideoDecoder* decoder); - virtual void OnStop(media::FilterCallback* callback); + virtual void OnStop(const base::Closure& callback); virtual void OnFrameAvailable(); private: diff --git a/media/tools/shader_bench/shader_bench.cc b/media/tools/shader_bench/shader_bench.cc index 23ff542..0cba70b 100644 --- a/media/tools/shader_bench/shader_bench.cc +++ b/media/tools/shader_bench/shader_bench.cc @@ -8,11 +8,11 @@ #include <stdlib.h> #include "base/at_exit.h" +#include "base/bind.h" #include "base/command_line.h" #include "base/memory/scoped_ptr.h" #include "base/string_number_conversions.h" #include "base/time.h" -#include "media/base/callback.h" #include "media/base/video_frame.h" #include "media/tools/shader_bench/cpu_color_painter.h" #include "media/tools/shader_bench/gpu_color_painter.h" @@ -82,7 +82,7 @@ void TestFinished() { void RunTest(media::Window* window, Painter* painter) { g_start_ = base::TimeTicks::HighResNow(); - window->Start(kNumFramesToPaint, NewRunnableFunction(&TestFinished), painter); + window->Start(kNumFramesToPaint, base::Bind(&TestFinished), painter); } int main(int argc, char** argv) { diff --git a/media/tools/shader_bench/window.cc b/media/tools/shader_bench/window.cc index b14a4c7..3eb26f4 100644 --- a/media/tools/shader_bench/window.cc +++ b/media/tools/shader_bench/window.cc @@ -1,20 +1,19 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "media/tools/shader_bench/window.h" -#include "base/task.h" - namespace media { Window::Window(int width, int height) - : done_task_(NULL), - painter_(NULL), + : painter_(NULL), limit_(0), count_(0), running_(false) { window_handle_ = CreateNativeWindow(width, height); } +Window::~Window() {} + } // namespace media diff --git a/media/tools/shader_bench/window.h b/media/tools/shader_bench/window.h index 3de1214..d66e849 100644 --- a/media/tools/shader_bench/window.h +++ b/media/tools/shader_bench/window.h @@ -1,20 +1,21 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MEDIA_TOOLS_SHADER_BENCH_WINDOW_H_ #define MEDIA_TOOLS_SHADER_BENCH_WINDOW_H_ +#include "base/callback.h" #include "ui/gfx/native_widget_types.h" class Painter; -class Task; namespace media { class Window { public: Window(int width, int height); + ~Window(); // Creates and returns a handle to a native window of the given dimensions. gfx::NativeWindow CreateNativeWindow(int width, int height); @@ -24,7 +25,7 @@ class Window { // Kicks off frame painting with the given limit, painter, and // callback to run when painting task is complete. - void Start(int limit, Task* done_task, Painter* painter); + void Start(int limit, const base::Closure& callback, Painter* painter); // Called when window is expected to paint self. void OnPaint(); @@ -33,9 +34,9 @@ class Window { void MainLoop(); private: - // Task to run when frame painting is completed. Will be deleted after + // Closure to run when frame painting is completed. Will be reset after // running. - Task* done_task_; + base::Closure callback_; // Reference to painter Window uses to paint frames. Painter* painter_; diff --git a/media/tools/shader_bench/window_linux.cc b/media/tools/shader_bench/window_linux.cc index 0063a8d..a0a3493 100644 --- a/media/tools/shader_bench/window_linux.cc +++ b/media/tools/shader_bench/window_linux.cc @@ -4,7 +4,6 @@ #include "media/tools/shader_bench/window.h" -#include "base/task.h" #include "media/tools/shader_bench/painter.h" #include <gdk/gdkx.h> @@ -41,11 +40,12 @@ gfx::PluginWindowHandle Window::PluginWindow() { return GDK_WINDOW_XWINDOW(GTK_WIDGET(window_handle_)->window); } -void Window::Start(int limit, Task* done_task, Painter* painter) { +void Window::Start(int limit, const base::Closure& callback, + Painter* painter) { running_ = true; count_ = 0; limit_ = limit; - done_task_ = done_task; + callback_ = callback; painter_ = painter; gtk_signal_connect(GTK_OBJECT(window_handle_), @@ -72,9 +72,9 @@ void Window::OnPaint() { gtk_widget_queue_draw(GTK_WIDGET(window_handle_)); } else { running_ = false; - if (done_task_) { - done_task_->Run(); - delete done_task_; + if (!callback_.is_null()) { + callback_.Run(); + callback_.Reset(); } gtk_main_quit(); } diff --git a/media/tools/shader_bench/window_win.cc b/media/tools/shader_bench/window_win.cc index 827e210..39985a6 100644 --- a/media/tools/shader_bench/window_win.cc +++ b/media/tools/shader_bench/window_win.cc @@ -4,7 +4,6 @@ #include "media/tools/shader_bench/window.h" -#include "base/task.h" #include "media/tools/shader_bench/painter.h" namespace media { @@ -81,11 +80,12 @@ gfx::PluginWindowHandle Window::PluginWindow() { return window_handle_; } -void Window::Start(int limit, Task* done_task, Painter* painter) { +void Window::Start(int limit, const base::Closure& callback, + Painter* painter) { running_ = true; count_ = 0; limit_ = limit; - done_task_ = done_task; + callback_ = callback; painter_ = painter; SetWindowLongPtr(window_handle_, GWL_USERDATA, @@ -108,10 +108,10 @@ void Window::OnPaint() { count_++; } else { running_ = false; - if (done_task_) { + if (!callback_.is_null()) { ShowWindow(window_handle_, SW_HIDE); - done_task_->Run(); - delete done_task_; + callback_.Run(); + callback_.Reset(); } } } diff --git a/media/tools/tile_render_bench/tile_render_bench.cc b/media/tools/tile_render_bench/tile_render_bench.cc index d961ea1..4447954 100644 --- a/media/tools/tile_render_bench/tile_render_bench.cc +++ b/media/tools/tile_render_bench/tile_render_bench.cc @@ -14,6 +14,7 @@ #include "base/at_exit.h" #include "base/basictypes.h" +#include "base/bind.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "base/task.h" @@ -207,8 +208,7 @@ void RunTest() { 0, 0, kStartSize, kStartSize, 0 }; XSendEvent(g_display, g_window, False, ExposureMask, (XEvent*)&ev); - MessageLoop::current()->PostTask(FROM_HERE, - NewRunnableFunction(&RunTest)); + MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&RunTest)); } void ProcessEvents() { @@ -232,7 +232,7 @@ int main() { InitGLContext(); InitTest(); - loop.PostTask(FROM_HERE, NewRunnableFunction(&ProcessEvents)); + loop.PostTask(FROM_HERE, base::Bind(&ProcessEvents)); loop.Run(); // Cleanup GL. diff --git a/media/tools/wav_ola_test/wav_ola_test.cc b/media/tools/wav_ola_test/wav_ola_test.cc index d3a59a8..42517f1 100644 --- a/media/tools/wav_ola_test/wav_ola_test.cc +++ b/media/tools/wav_ola_test/wav_ola_test.cc @@ -12,7 +12,7 @@ #include <iostream> #include <string> -#include "base/callback.h" +#include "base/bind.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/memory/ref_counted.h" @@ -122,8 +122,7 @@ int main(int argc, const char** argv) { // Instantiate dummy class and callback to feed data to |ola|. Dummy guy(input.get(), &ola, window_size); - AudioRendererAlgorithmOLA::RequestReadCallback* cb = - NewCallback(&guy, &Dummy::ReadDataForAlg); + base::Closure cb = base::Bind(&Dummy::ReadDataForAlg, base::Unretained(&guy)); ola.Initialize(wav.channels, wav.sample_rate, wav.bit_rate, diff --git a/media/video/capture/fake_video_capture_device.cc b/media/video/capture/fake_video_capture_device.cc index 9de3a40d..a74b4d3 100644 --- a/media/video/capture/fake_video_capture_device.cc +++ b/media/video/capture/fake_video_capture_device.cc @@ -6,6 +6,7 @@ #include <string> +#include "base/bind.h" #include "base/memory/scoped_ptr.h" #include "base/stringprintf.h" @@ -87,7 +88,8 @@ void FakeVideoCaptureDevice::Start() { capture_thread_.Start(); capture_thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &FakeVideoCaptureDevice::OnCaptureTask)); + base::Bind(&FakeVideoCaptureDevice::OnCaptureTask, + base::Unretained(this))); } void FakeVideoCaptureDevice::Stop() { @@ -121,7 +123,8 @@ void FakeVideoCaptureDevice::OnCaptureTask() { // Reschedule next CaptureTask. capture_thread_.message_loop()->PostDelayedTask( FROM_HERE, - NewRunnableMethod(this, &FakeVideoCaptureDevice::OnCaptureTask), + base::Bind(&FakeVideoCaptureDevice::OnCaptureTask, + base::Unretained(this)), kFakeCaptureTimeoutMs); } diff --git a/media/video/capture/linux/video_capture_device_linux.cc b/media/video/capture/linux/video_capture_device_linux.cc index 3062e6e..c70ba3c 100644 --- a/media/video/capture/linux/video_capture_device_linux.cc +++ b/media/video/capture/linux/video_capture_device_linux.cc @@ -12,6 +12,7 @@ #include <string> +#include "base/bind.h" #include "base/file_util.h" #include "base/stringprintf.h" @@ -142,8 +143,8 @@ void VideoCaptureDeviceLinux::Allocate(int width, v4l2_thread_.Start(); v4l2_thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &VideoCaptureDeviceLinux::OnAllocate, - width, height, frame_rate, observer)); + base::Bind(&VideoCaptureDeviceLinux::OnAllocate, base::Unretained(this), + width, height, frame_rate, observer)); } void VideoCaptureDeviceLinux::Start() { @@ -152,7 +153,7 @@ void VideoCaptureDeviceLinux::Start() { } v4l2_thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &VideoCaptureDeviceLinux::OnStart)); + base::Bind(&VideoCaptureDeviceLinux::OnStart, base::Unretained(this))); } void VideoCaptureDeviceLinux::Stop() { @@ -161,7 +162,7 @@ void VideoCaptureDeviceLinux::Stop() { } v4l2_thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &VideoCaptureDeviceLinux::OnStop)); + base::Bind(&VideoCaptureDeviceLinux::OnStop, base::Unretained(this))); } void VideoCaptureDeviceLinux::DeAllocate() { @@ -170,7 +171,8 @@ void VideoCaptureDeviceLinux::DeAllocate() { } v4l2_thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &VideoCaptureDeviceLinux::OnDeAllocate)); + base::Bind(&VideoCaptureDeviceLinux::OnDeAllocate, + base::Unretained(this))); v4l2_thread_.Stop(); // Make sure no buffers are still allocated. @@ -297,7 +299,8 @@ void VideoCaptureDeviceLinux::OnStart() { // Post task to start fetching frames from v4l2. v4l2_thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &VideoCaptureDeviceLinux::OnCaptureTask)); + base::Bind(&VideoCaptureDeviceLinux::OnCaptureTask, + base::Unretained(this))); } void VideoCaptureDeviceLinux::OnStop() { @@ -342,7 +345,8 @@ void VideoCaptureDeviceLinux::OnCaptureTask() { } v4l2_thread_.message_loop()->PostDelayedTask( FROM_HERE, - NewRunnableMethod(this, &VideoCaptureDeviceLinux::OnCaptureTask), + base::Bind(&VideoCaptureDeviceLinux::OnCaptureTask, + base::Unretained(this)), kCaptureSelectWaitMs); } @@ -368,7 +372,8 @@ void VideoCaptureDeviceLinux::OnCaptureTask() { v4l2_thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &VideoCaptureDeviceLinux::OnCaptureTask)); + base::Bind(&VideoCaptureDeviceLinux::OnCaptureTask, + base::Unretained(this))); } bool VideoCaptureDeviceLinux::AllocateVideoBuffers() { diff --git a/media/video/capture/video_capture_proxy.cc b/media/video/capture/video_capture_proxy.cc index 221f2c6..463d77f 100644 --- a/media/video/capture/video_capture_proxy.cc +++ b/media/video/capture/video_capture_proxy.cc @@ -4,6 +4,7 @@ #include "media/video/capture/video_capture_proxy.h" +#include "base/bind.h" #include "base/location.h" #include "base/message_loop_proxy.h" @@ -36,42 +37,42 @@ VideoCaptureHandlerProxy::~VideoCaptureHandlerProxy() { } void VideoCaptureHandlerProxy::OnStarted(VideoCapture* capture) { - main_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, + main_message_loop_->PostTask(FROM_HERE, base::Bind( &VideoCaptureHandlerProxy::OnStartedOnMainThread, + base::Unretained(this), capture, GetState(capture))); } void VideoCaptureHandlerProxy::OnStopped(VideoCapture* capture) { - main_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, + main_message_loop_->PostTask(FROM_HERE, base::Bind( &VideoCaptureHandlerProxy::OnStoppedOnMainThread, + base::Unretained(this), capture, GetState(capture))); } void VideoCaptureHandlerProxy::OnPaused(VideoCapture* capture) { - main_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, + main_message_loop_->PostTask(FROM_HERE, base::Bind( &VideoCaptureHandlerProxy::OnPausedOnMainThread, + base::Unretained(this), capture, GetState(capture))); } void VideoCaptureHandlerProxy::OnError(VideoCapture* capture, int error_code) { - main_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, + main_message_loop_->PostTask(FROM_HERE, base::Bind( &VideoCaptureHandlerProxy::OnErrorOnMainThread, + base::Unretained(this), capture, GetState(capture), error_code)); } void VideoCaptureHandlerProxy::OnRemoved(VideoCapture* capture) { - main_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, + main_message_loop_->PostTask(FROM_HERE, base::Bind( &VideoCaptureHandlerProxy::OnRemovedOnMainThread, + base::Unretained(this), capture, GetState(capture))); } @@ -79,9 +80,9 @@ void VideoCaptureHandlerProxy::OnRemoved(VideoCapture* capture) { void VideoCaptureHandlerProxy::OnBufferReady( VideoCapture* capture, scoped_refptr<VideoCapture::VideoFrameBuffer> buffer) { - main_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, + main_message_loop_->PostTask(FROM_HERE, base::Bind( &VideoCaptureHandlerProxy::OnBufferReadyOnMainThread, + base::Unretained(this), capture, GetState(capture), buffer)); @@ -90,9 +91,9 @@ void VideoCaptureHandlerProxy::OnBufferReady( void VideoCaptureHandlerProxy::OnDeviceInfoReceived( VideoCapture* capture, const VideoCaptureParams& device_info) { - main_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, + main_message_loop_->PostTask(FROM_HERE, base::Bind( &VideoCaptureHandlerProxy::OnDeviceInfoReceivedOnMainThread, + base::Unretained(this), capture, GetState(capture), device_info)); diff --git a/media/video/ffmpeg_video_decode_engine.cc b/media/video/ffmpeg_video_decode_engine.cc index 65edc2f..9a89262 100644 --- a/media/video/ffmpeg_video_decode_engine.cc +++ b/media/video/ffmpeg_video_decode_engine.cc @@ -8,7 +8,6 @@ #include "base/string_number_conversions.h" #include "base/task.h" #include "media/base/buffers.h" -#include "media/base/callback.h" #include "media/base/limits.h" #include "media/base/media_switches.h" #include "media/base/pipeline.h" |