diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/base/android/media_decoder_job.cc | 52 | ||||
-rw-r--r-- | media/base/android/media_decoder_job.h | 15 | ||||
-rw-r--r-- | media/base/android/media_player_listener.cc | 22 | ||||
-rw-r--r-- | media/base/android/media_player_listener.h | 8 | ||||
-rw-r--r-- | media/base/fake_text_track_stream.cc | 4 | ||||
-rw-r--r-- | media/base/fake_text_track_stream.h | 2 | ||||
-rw-r--r-- | media/base/pipeline.cc | 90 | ||||
-rw-r--r-- | media/base/pipeline.h | 22 | ||||
-rw-r--r-- | media/base/serial_runner.cc | 19 | ||||
-rw-r--r-- | media/base/serial_runner.h | 4 | ||||
-rw-r--r-- | media/base/text_renderer.cc | 30 | ||||
-rw-r--r-- | media/base/text_renderer.h | 11 |
12 files changed, 142 insertions, 137 deletions
diff --git a/media/base/android/media_decoder_job.cc b/media/base/android/media_decoder_job.cc index c6ad9bb..75b72ce 100644 --- a/media/base/android/media_decoder_job.cc +++ b/media/base/android/media_decoder_job.cc @@ -7,7 +7,7 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/debug/trace_event.h" -#include "base/message_loop/message_loop.h" +#include "base/message_loop/message_loop_proxy.h" #include "media/base/android/media_codec_bridge.h" #include "media/base/bind_to_loop.h" #include "media/base/buffers.h" @@ -20,11 +20,11 @@ namespace media { static const int kMediaCodecTimeoutInMilliseconds = 250; MediaDecoderJob::MediaDecoderJob( - const scoped_refptr<base::MessageLoopProxy>& decoder_loop, + const scoped_refptr<base::SingleThreadTaskRunner>& decoder_task_runner, MediaCodecBridge* media_codec_bridge, const base::Closure& request_data_cb) - : ui_loop_(base::MessageLoopProxy::current()), - decoder_loop_(decoder_loop), + : ui_task_runner_(base::MessageLoopProxy::current()), + decoder_task_runner_(decoder_task_runner), media_codec_bridge_(media_codec_bridge), needs_flush_(false), input_eos_encountered_(false), @@ -43,7 +43,7 @@ MediaDecoderJob::~MediaDecoderJob() {} void MediaDecoderJob::OnDataReceived(const DemuxerData& data) { DVLOG(1) << __FUNCTION__ << ": " << data.access_units.size() << " units"; - DCHECK(ui_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); DCHECK(!on_data_received_cb_.is_null()); TRACE_EVENT_ASYNC_END2( @@ -64,13 +64,13 @@ void MediaDecoderJob::OnDataReceived(const DemuxerData& data) { } void MediaDecoderJob::Prefetch(const base::Closure& prefetch_cb) { - DCHECK(ui_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); DCHECK(on_data_received_cb_.is_null()); DCHECK(decode_cb_.is_null()); if (HasData()) { DVLOG(1) << __FUNCTION__ << " : using previously received data"; - ui_loop_->PostTask(FROM_HERE, prefetch_cb); + ui_task_runner_->PostTask(FROM_HERE, prefetch_cb); return; } @@ -84,7 +84,7 @@ bool MediaDecoderJob::Decode( const DecoderCallback& callback) { DCHECK(decode_cb_.is_null()); DCHECK(on_data_received_cb_.is_null()); - DCHECK(ui_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); decode_cb_ = callback; @@ -110,7 +110,7 @@ bool MediaDecoderJob::Decode( } void MediaDecoderJob::StopDecode() { - DCHECK(ui_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); DCHECK(is_decoding()); stop_decode_pending_ = true; } @@ -129,7 +129,7 @@ void MediaDecoderJob::Flush() { void MediaDecoderJob::BeginPrerolling( const base::TimeDelta& preroll_timestamp) { DVLOG(1) << __FUNCTION__ << "(" << preroll_timestamp.InSecondsF() << ")"; - DCHECK(ui_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); DCHECK(!is_decoding()); preroll_timestamp_ = preroll_timestamp; @@ -137,7 +137,7 @@ void MediaDecoderJob::BeginPrerolling( } void MediaDecoderJob::Release() { - DCHECK(ui_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); DVLOG(1) << __FUNCTION__; // If the decoder job is not waiting for data, and is still decoding, we @@ -158,7 +158,7 @@ void MediaDecoderJob::Release() { MediaCodecStatus MediaDecoderJob::QueueInputBuffer(const AccessUnit& unit) { DVLOG(1) << __FUNCTION__; - DCHECK(decoder_loop_->BelongsToCurrentThread()); + DCHECK(decoder_task_runner_->BelongsToCurrentThread()); TRACE_EVENT0("media", __FUNCTION__); int input_buf_index = input_buf_index_; @@ -207,7 +207,7 @@ MediaCodecStatus MediaDecoderJob::QueueInputBuffer(const AccessUnit& unit) { } bool MediaDecoderJob::HasData() const { - DCHECK(ui_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); // When |input_eos_encountered_| is set, |access_units| must not be empty and // |access_unit_index_| must be pointing to an EOS unit. We'll reuse this // unit to flush the decoder until we hit output EOS. @@ -222,7 +222,7 @@ bool MediaDecoderJob::HasData() const { void MediaDecoderJob::RequestData(const base::Closure& done_cb) { DVLOG(1) << __FUNCTION__; - DCHECK(ui_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); DCHECK(on_data_received_cb_.is_null()); DCHECK(!input_eos_encountered_); @@ -238,27 +238,27 @@ void MediaDecoderJob::RequestData(const base::Closure& done_cb) { void MediaDecoderJob::DecodeNextAccessUnit( const base::TimeTicks& start_time_ticks, const base::TimeDelta& start_presentation_timestamp) { - DCHECK(ui_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); DCHECK(!decode_cb_.is_null()); // If the first access unit is a config change, request the player to dequeue // the input buffer again so that it can request config data. if (received_data_.access_units[access_unit_index_].status == DemuxerStream::kConfigChanged) { - ui_loop_->PostTask(FROM_HERE, - base::Bind(&MediaDecoderJob::OnDecodeCompleted, - base::Unretained(this), - MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER, - kNoTimestamp(), - 0)); + ui_task_runner_->PostTask(FROM_HERE, + base::Bind(&MediaDecoderJob::OnDecodeCompleted, + base::Unretained(this), + MEDIA_CODEC_DEQUEUE_INPUT_AGAIN_LATER, + kNoTimestamp(), + 0)); return; } - decoder_loop_->PostTask(FROM_HERE, base::Bind( + decoder_task_runner_->PostTask(FROM_HERE, base::Bind( &MediaDecoderJob::DecodeInternal, base::Unretained(this), received_data_.access_units[access_unit_index_], start_time_ticks, start_presentation_timestamp, needs_flush_, - media::BindToLoop(ui_loop_, base::Bind( + media::BindToLoop(ui_task_runner_, base::Bind( &MediaDecoderJob::OnDecodeCompleted, base::Unretained(this))))); needs_flush_ = false; } @@ -270,7 +270,7 @@ void MediaDecoderJob::DecodeInternal( bool needs_flush, const MediaDecoderJob::DecoderCallback& callback) { DVLOG(1) << __FUNCTION__; - DCHECK(decoder_loop_->BelongsToCurrentThread()); + DCHECK(decoder_task_runner_->BelongsToCurrentThread()); TRACE_EVENT0("media", __FUNCTION__); if (needs_flush) { @@ -367,7 +367,7 @@ void MediaDecoderJob::DecodeInternal( } if (time_to_render > base::TimeDelta()) { - decoder_loop_->PostDelayedTask( + decoder_task_runner_->PostDelayedTask( FROM_HERE, base::Bind(&MediaDecoderJob::ReleaseOutputBuffer, weak_this_.GetWeakPtr(), buffer_index, size, render_output, @@ -397,7 +397,7 @@ void MediaDecoderJob::DecodeInternal( void MediaDecoderJob::OnDecodeCompleted( MediaCodecStatus status, const base::TimeDelta& presentation_timestamp, size_t audio_output_bytes) { - DCHECK(ui_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); if (destroy_pending_) { DVLOG(1) << __FUNCTION__ << " : completing pending deletion"; diff --git a/media/base/android/media_decoder_job.h b/media/base/android/media_decoder_job.h index 6ee086d..286d27c 100644 --- a/media/base/android/media_decoder_job.h +++ b/media/base/android/media_decoder_job.h @@ -12,7 +12,7 @@ #include "media/base/android/media_codec_bridge.h" namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; } namespace media { @@ -77,9 +77,10 @@ class MediaDecoderJob { bool is_decoding() const { return !decode_cb_.is_null(); } protected: - MediaDecoderJob(const scoped_refptr<base::MessageLoopProxy>& decoder_loop, - MediaCodecBridge* media_codec_bridge, - const base::Closure& request_data_cb); + MediaDecoderJob( + const scoped_refptr<base::SingleThreadTaskRunner>& decoder_task_runner, + MediaCodecBridge* media_codec_bridge, + const base::Closure& request_data_cb); // Release the output buffer at index |output_buffer_index| and render it if // |render_output| is true. Upon completion, |callback| will be called. @@ -131,10 +132,10 @@ class MediaDecoderJob { size_t audio_output_bytes); // The UI message loop where callbacks should be dispatched. - scoped_refptr<base::MessageLoopProxy> ui_loop_; + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; - // The message loop that decoder job runs on. - scoped_refptr<base::MessageLoopProxy> decoder_loop_; + // The task runner that decoder job runs on. + scoped_refptr<base::SingleThreadTaskRunner> decoder_task_runner_; // The media codec bridge used for decoding. Owned by derived class. // NOTE: This MUST NOT be accessed in the destructor. diff --git a/media/base/android/media_player_listener.cc b/media/base/android/media_player_listener.cc index c269840..6a22298 100644 --- a/media/base/android/media_player_listener.cc +++ b/media/base/android/media_player_listener.cc @@ -7,7 +7,7 @@ #include "base/android/jni_android.h" #include "base/bind.h" #include "base/logging.h" -#include "base/message_loop/message_loop_proxy.h" +#include "base/single_thread_task_runner.h" #include "media/base/android/media_player_bridge.h" // Auto generated jni class from MediaPlayerListener.java. @@ -21,11 +21,11 @@ using base::android::ScopedJavaLocalRef; namespace media { MediaPlayerListener::MediaPlayerListener( - const scoped_refptr<base::MessageLoopProxy>& message_loop, + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, base::WeakPtr<MediaPlayerBridge> media_player) - : message_loop_(message_loop), + : task_runner_(task_runner), media_player_(media_player) { - DCHECK(message_loop_.get()); + DCHECK(task_runner_.get()); DCHECK(media_player_); } @@ -53,44 +53,44 @@ void MediaPlayerListener::ReleaseMediaPlayerListenerResources() { void MediaPlayerListener::OnMediaError( JNIEnv* /* env */, jobject /* obj */, jint error_type) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &MediaPlayerBridge::OnMediaError, media_player_, error_type)); } void MediaPlayerListener::OnVideoSizeChanged( JNIEnv* /* env */, jobject /* obj */, jint width, jint height) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &MediaPlayerBridge::OnVideoSizeChanged, media_player_, width, height)); } void MediaPlayerListener::OnBufferingUpdate( JNIEnv* /* env */, jobject /* obj */, jint percent) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &MediaPlayerBridge::OnBufferingUpdate, media_player_, percent)); } void MediaPlayerListener::OnPlaybackComplete( JNIEnv* /* env */, jobject /* obj */) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &MediaPlayerBridge::OnPlaybackComplete, media_player_)); } void MediaPlayerListener::OnSeekComplete( JNIEnv* /* env */, jobject /* obj */) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &MediaPlayerBridge::OnSeekComplete, media_player_)); } void MediaPlayerListener::OnMediaPrepared( JNIEnv* /* env */, jobject /* obj */) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &MediaPlayerBridge::OnMediaPrepared, media_player_)); } void MediaPlayerListener::OnMediaInterrupted( JNIEnv* /* env */, jobject /* obj */) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &MediaPlayerBridge::OnMediaInterrupted, media_player_)); } diff --git a/media/base/android/media_player_listener.h b/media/base/android/media_player_listener.h index 698493b..46e56db 100644 --- a/media/base/android/media_player_listener.h +++ b/media/base/android/media_player_listener.h @@ -12,7 +12,7 @@ #include "base/memory/weak_ptr.h" namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; } namespace media { @@ -25,9 +25,9 @@ class MediaPlayerListener { public: // Construct a native MediaPlayerListener object. Callbacks from the java // side object will be forwarded to |media_player| by posting a task on the - // |message_loop|. + // |task_runner|. MediaPlayerListener( - const scoped_refptr<base::MessageLoopProxy>& message_loop, + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, base::WeakPtr<MediaPlayerBridge> media_player); virtual ~MediaPlayerListener(); @@ -51,7 +51,7 @@ class MediaPlayerListener { private: // The message loop where |media_player_| lives. - scoped_refptr<base::MessageLoopProxy> message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; // The MediaPlayerBridge object all the callbacks should be send to. base::WeakPtr<MediaPlayerBridge> media_player_; diff --git a/media/base/fake_text_track_stream.cc b/media/base/fake_text_track_stream.cc index 3136c47..c37b1b5 100644 --- a/media/base/fake_text_track_stream.cc +++ b/media/base/fake_text_track_stream.cc @@ -12,7 +12,7 @@ namespace media { FakeTextTrackStream::FakeTextTrackStream() - : message_loop_(base::MessageLoopProxy::current()), + : task_runner_(base::MessageLoopProxy::current()), stopping_(false) { } @@ -27,7 +27,7 @@ void FakeTextTrackStream::Read(const ReadCB& read_cb) { read_cb_ = read_cb; if (stopping_) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &FakeTextTrackStream::AbortPendingRead, base::Unretained(this))); } } diff --git a/media/base/fake_text_track_stream.h b/media/base/fake_text_track_stream.h index 33c74ef..88c1366 100644 --- a/media/base/fake_text_track_stream.h +++ b/media/base/fake_text_track_stream.h @@ -37,7 +37,7 @@ class FakeTextTrackStream : public DemuxerStream { MOCK_METHOD0(OnRead, void()); private: - scoped_refptr<base::MessageLoopProxy> message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; ReadCB read_cb_; bool stopping_; diff --git a/media/base/pipeline.cc b/media/base/pipeline.cc index 5799dc3..aefaedc8 100644 --- a/media/base/pipeline.cc +++ b/media/base/pipeline.cc @@ -10,8 +10,9 @@ #include "base/callback.h" #include "base/callback_helpers.h" #include "base/compiler_specific.h" -#include "base/message_loop/message_loop.h" +#include "base/location.h" #include "base/metrics/histogram.h" +#include "base/single_thread_task_runner.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" @@ -31,9 +32,10 @@ using base::TimeDelta; namespace media { -Pipeline::Pipeline(const scoped_refptr<base::MessageLoopProxy>& message_loop, - MediaLog* media_log) - : message_loop_(message_loop), +Pipeline::Pipeline( + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, + MediaLog* media_log) + : task_runner_(task_runner), media_log_(media_log), running_(false), did_loading_progress_(false), @@ -80,14 +82,14 @@ void Pipeline::Start(scoped_ptr<FilterCollection> collection, DCHECK(!buffering_state_cb.is_null()); running_ = true; - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::StartTask, base::Unretained(this), base::Passed(&collection), ended_cb, error_cb, seek_cb, buffering_state_cb, duration_change_cb)); } void Pipeline::Stop(const base::Closure& stop_cb) { base::AutoLock auto_lock(lock_); - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::StopTask, base::Unretained(this), stop_cb)); } @@ -98,7 +100,7 @@ void Pipeline::Seek(TimeDelta time, const PipelineStatusCB& seek_cb) { return; } - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::SeekTask, base::Unretained(this), time, seek_cb)); } @@ -129,7 +131,7 @@ void Pipeline::SetPlaybackRate(float playback_rate) { base::AutoLock auto_lock(lock_); playback_rate_ = playback_rate; if (running_) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::PlaybackRateChangedTask, base::Unretained(this), playback_rate)); } @@ -147,7 +149,7 @@ void Pipeline::SetVolume(float volume) { base::AutoLock auto_lock(lock_); volume_ = volume; if (running_) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::VolumeChangedTask, base::Unretained(this), volume)); } } @@ -249,7 +251,7 @@ const char* Pipeline::GetStateString(State state) { #undef RETURN_STRING Pipeline::State Pipeline::GetNextState() const { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(stop_cb_.is_null()) << "State transitions don't happen when stopping"; DCHECK_EQ(status_, PIPELINE_OK) @@ -298,13 +300,13 @@ void Pipeline::OnDemuxerError(PipelineStatus error) { void Pipeline::AddTextStream(DemuxerStream* text_stream, const TextTrackConfig& config) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::AddTextStreamTask, base::Unretained(this), text_stream, config)); } void Pipeline::RemoveTextStream(DemuxerStream* text_stream) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::RemoveTextStreamTask, base::Unretained(this), text_stream)); } @@ -314,7 +316,7 @@ void Pipeline::SetError(PipelineStatus error) { DCHECK_NE(PIPELINE_OK, error); VLOG(1) << "Media pipeline error: " << error; - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::ErrorChangedTask, base::Unretained(this), error)); media_log_->AddEvent(media_log_->CreatePipelineErrorEvent(error)); @@ -322,7 +324,7 @@ void Pipeline::SetError(PipelineStatus error) { void Pipeline::OnAudioDisabled() { DCHECK(IsRunning()); - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::AudioDisabledTask, base::Unretained(this))); media_log_->AddEvent( media_log_->CreateEvent(MediaLogEvent::AUDIO_RENDERER_DISABLED)); @@ -411,12 +413,12 @@ TimeDelta Pipeline::TimeForByteOffset_Locked(int64 byte_offset) const { void Pipeline::OnStateTransition(PipelineStatus status) { // Force post to process state transitions after current execution frame. - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::StateTransitionTask, base::Unretained(this), status)); } void Pipeline::StateTransitionTask(PipelineStatus status) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); // No-op any state transitions if we're stopping. if (state_ == kStopping || state_ == kStopped) @@ -519,7 +521,7 @@ void Pipeline::StateTransitionTask(PipelineStatus status) { // That being said, deleting the renderers while keeping |pending_callbacks_| // running on the media thread would result in crashes. void Pipeline::DoInitialPreroll(const PipelineStatusCB& done_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(!pending_callbacks_.get()); SerialRunner::Queue bound_fns; @@ -544,7 +546,7 @@ void Pipeline::DoInitialPreroll(const PipelineStatusCB& done_cb) { void Pipeline::DoSeek( base::TimeDelta seek_timestamp, const PipelineStatusCB& done_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(!pending_callbacks_.get()); SerialRunner::Queue bound_fns; @@ -597,7 +599,7 @@ void Pipeline::DoSeek( } void Pipeline::DoPlay(const PipelineStatusCB& done_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(!pending_callbacks_.get()); SerialRunner::Queue bound_fns; @@ -623,7 +625,7 @@ void Pipeline::DoPlay(const PipelineStatusCB& done_cb) { } void Pipeline::DoStop(const PipelineStatusCB& done_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(!pending_callbacks_.get()); SerialRunner::Queue bound_fns; @@ -651,7 +653,7 @@ void Pipeline::DoStop(const PipelineStatusCB& done_cb) { } void Pipeline::OnStopCompleted(PipelineStatus status) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kStopping); { base::AutoLock l(lock_); @@ -711,22 +713,22 @@ void Pipeline::OnNaturalVideoSizeChanged(const gfx::Size& size) { } void Pipeline::OnAudioRendererEnded() { - // Force post to process ended messages after current execution frame. - message_loop_->PostTask(FROM_HERE, base::Bind( + // Force post to process ended tasks after current execution frame. + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::DoAudioRendererEnded, base::Unretained(this))); media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::AUDIO_ENDED)); } void Pipeline::OnVideoRendererEnded() { - // Force post to process ended messages after current execution frame. - message_loop_->PostTask(FROM_HERE, base::Bind( + // Force post to process ended tasks after current execution frame. + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::DoVideoRendererEnded, base::Unretained(this))); media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::VIDEO_ENDED)); } void Pipeline::OnTextRendererEnded() { // Force post to process ended messages after current execution frame. - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::DoTextRendererEnded, base::Unretained(this))); media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::TEXT_ENDED)); } @@ -746,7 +748,7 @@ void Pipeline::StartTask(scoped_ptr<FilterCollection> filter_collection, const PipelineStatusCB& seek_cb, const BufferingStateCB& buffering_state_cb, const base::Closure& duration_change_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); CHECK_EQ(kCreated, state_) << "Media pipeline cannot be started more than once"; @@ -768,7 +770,7 @@ void Pipeline::StartTask(scoped_ptr<FilterCollection> filter_collection, } void Pipeline::StopTask(const base::Closure& stop_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(stop_cb_.is_null()); if (state_ == kStopped) { @@ -788,7 +790,7 @@ void Pipeline::StopTask(const base::Closure& stop_cb) { } void Pipeline::ErrorChangedTask(PipelineStatus error) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!"; if (state_ == kStopping || state_ == kStopped) @@ -802,7 +804,7 @@ void Pipeline::ErrorChangedTask(PipelineStatus error) { } void Pipeline::PlaybackRateChangedTask(float playback_rate) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); // Playback rate changes are only carried out while playing. if (state_ != kStarting && state_ != kStarted) @@ -820,7 +822,7 @@ void Pipeline::PlaybackRateChangedTask(float playback_rate) { } void Pipeline::VolumeChangedTask(float volume) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); // Volume changes are only carried out while playing. if (state_ != kStarting && state_ != kStarted) @@ -831,7 +833,7 @@ void Pipeline::VolumeChangedTask(float volume) { } void Pipeline::SeekTask(TimeDelta time, const PipelineStatusCB& seek_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(stop_cb_.is_null()); // Suppress seeking if we're not fully started. @@ -867,7 +869,7 @@ void Pipeline::SeekTask(TimeDelta time, const PipelineStatusCB& seek_cb) { } void Pipeline::DoAudioRendererEnded() { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); if (state_ != kStarted) return; @@ -886,7 +888,7 @@ void Pipeline::DoAudioRendererEnded() { } void Pipeline::DoVideoRendererEnded() { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); if (state_ != kStarted) return; @@ -898,7 +900,7 @@ void Pipeline::DoVideoRendererEnded() { } void Pipeline::DoTextRendererEnded() { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); if (state_ != kStarted) return; @@ -910,7 +912,7 @@ void Pipeline::DoTextRendererEnded() { } void Pipeline::RunEndedCallbackIfNeeded() { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); if (audio_renderer_ && !audio_ended_ && !audio_disabled_) return; @@ -931,7 +933,7 @@ void Pipeline::RunEndedCallbackIfNeeded() { } void Pipeline::AudioDisabledTask() { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); base::AutoLock auto_lock(lock_); has_audio_ = false; @@ -947,26 +949,26 @@ void Pipeline::AudioDisabledTask() { void Pipeline::AddTextStreamTask(DemuxerStream* text_stream, const TextTrackConfig& config) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); // TODO(matthewjheaney): fix up text_ended_ when text stream // is added (http://crbug.com/321446). text_renderer_->AddTextStream(text_stream, config); } void Pipeline::RemoveTextStreamTask(DemuxerStream* text_stream) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); text_renderer_->RemoveTextStream(text_stream); } void Pipeline::InitializeDemuxer(const PipelineStatusCB& done_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); demuxer_ = filter_collection_->GetDemuxer(); demuxer_->Initialize(this, done_cb, text_renderer_); } void Pipeline::InitializeAudioRenderer(const PipelineStatusCB& done_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); audio_renderer_ = filter_collection_->GetAudioRenderer(); audio_renderer_->Initialize( @@ -981,7 +983,7 @@ void Pipeline::InitializeAudioRenderer(const PipelineStatusCB& done_cb) { } void Pipeline::InitializeVideoRenderer(const PipelineStatusCB& done_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::VIDEO); @@ -1006,8 +1008,8 @@ void Pipeline::InitializeVideoRenderer(const PipelineStatusCB& done_cb) { } void Pipeline::OnAudioUnderflow() { - if (!message_loop_->BelongsToCurrentThread()) { - message_loop_->PostTask(FROM_HERE, base::Bind( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask(FROM_HERE, base::Bind( &Pipeline::OnAudioUnderflow, base::Unretained(this))); return; } diff --git a/media/base/pipeline.h b/media/base/pipeline.h index 222091f..bb91d29 100644 --- a/media/base/pipeline.h +++ b/media/base/pipeline.h @@ -21,7 +21,7 @@ #include "ui/gfx/size.h" namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; class TimeDelta; } @@ -35,7 +35,7 @@ class TextTrackConfig; class VideoRenderer; // Pipeline runs the media pipeline. Filters are created and called on the -// message loop injected into this object. Pipeline works like a state +// task runner injected into this object. Pipeline works like a state // machine to perform asynchronous initialization, pausing, seeking and playing. // // Here's a state diagram that describes the lifetime of this object. @@ -82,8 +82,8 @@ class MEDIA_EXPORT Pipeline : public DemuxerHost { typedef base::Callback<void(BufferingState)> BufferingStateCB; - // Constructs a media pipeline that will execute on |message_loop|. - Pipeline(const scoped_refptr<base::MessageLoopProxy>& message_loop, + // Constructs a media pipeline that will execute on |task_runner|. + Pipeline(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, MediaLog* media_log); virtual ~Pipeline(); @@ -264,8 +264,8 @@ class MEDIA_EXPORT Pipeline : public DemuxerHost { void OnVideoTimeUpdate(base::TimeDelta max_time); // The following "task" methods correspond to the public methods, but these - // methods are run as the result of posting a task to the PipelineInternal's - // message loop. + // methods are run as the result of posting a task to the Pipeline's + // task runner. void StartTask(scoped_ptr<FilterCollection> filter_collection, const base::Closure& ended_cb, const PipelineStatusCB& error_cb, @@ -351,8 +351,8 @@ class MEDIA_EXPORT Pipeline : public DemuxerHost { void StartClockIfWaitingForTimeUpdate_Locked(); - // Message loop used to execute pipeline tasks. - scoped_refptr<base::MessageLoopProxy> message_loop_; + // Task runner used to execute pipeline tasks. + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; // MediaLog to which to log events. scoped_refptr<MediaLog> media_log_; @@ -378,12 +378,12 @@ class MEDIA_EXPORT Pipeline : public DemuxerHost { gfx::Size natural_size_; // Current volume level (from 0.0f to 1.0f). This value is set immediately - // via SetVolume() and a task is dispatched on the message loop to notify the + // via SetVolume() and a task is dispatched on the task runner to notify the // filters. float volume_; // Current playback rate (>= 0.0f). This value is set immediately via - // SetPlaybackRate() and a task is dispatched on the message loop to notify + // SetPlaybackRate() and a task is dispatched on the task runner to notify // the filters. float playback_rate_; @@ -414,7 +414,7 @@ class MEDIA_EXPORT Pipeline : public DemuxerHost { bool has_video_; // The following data members are only accessed by tasks posted to - // |message_loop_|. + // |task_runner_|. // Member that tracks the current state. State state_; diff --git a/media/base/serial_runner.cc b/media/base/serial_runner.cc index dfc4a0b..0af441a 100644 --- a/media/base/serial_runner.cc +++ b/media/base/serial_runner.cc @@ -6,8 +6,9 @@ #include "base/bind.h" #include "base/callback_helpers.h" -#include "base/message_loop/message_loop.h" +#include "base/location.h" #include "base/message_loop/message_loop_proxy.h" +#include "base/single_thread_task_runner.h" namespace media { @@ -20,14 +21,14 @@ static void RunBoundClosure( bound_closure.Run(base::Bind(status_cb, PIPELINE_OK)); } -// Runs |status_cb| with |last_status| on |message_loop|. -static void RunOnMessageLoop( - const scoped_refptr<base::MessageLoopProxy>& message_loop, +// Runs |status_cb| with |last_status| on |task_runner|. +static void RunOnTaskRunner( + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, const PipelineStatusCB& status_cb, PipelineStatus last_status) { // Force post to permit cancellation of a series in the scenario where all // bound functions run on the same thread. - message_loop->PostTask(FROM_HERE, base::Bind(status_cb, last_status)); + task_runner->PostTask(FROM_HERE, base::Bind(status_cb, last_status)); } SerialRunner::Queue::Queue() {} @@ -56,13 +57,13 @@ bool SerialRunner::Queue::empty() { SerialRunner::SerialRunner( const Queue& bound_fns, const PipelineStatusCB& done_cb) : weak_this_(this), - message_loop_(base::MessageLoopProxy::current()), + task_runner_(base::MessageLoopProxy::current()), bound_fns_(bound_fns), done_cb_(done_cb) { // Respect both cancellation and calling stack guarantees for |done_cb| // when empty. if (bound_fns_.empty()) { - message_loop_->PostTask(FROM_HERE, base::Bind( + task_runner_->PostTask(FROM_HERE, base::Bind( &SerialRunner::RunNextInSeries, weak_this_.GetWeakPtr(), PIPELINE_OK)); return; } @@ -80,7 +81,7 @@ scoped_ptr<SerialRunner> SerialRunner::Run( } void SerialRunner::RunNextInSeries(PipelineStatus last_status) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(!done_cb_.is_null()); if (bound_fns_.empty() || last_status != PIPELINE_OK) { @@ -89,7 +90,7 @@ void SerialRunner::RunNextInSeries(PipelineStatus last_status) { } BoundPipelineStatusCB bound_fn = bound_fns_.Pop(); - bound_fn.Run(base::Bind(&RunOnMessageLoop, message_loop_, base::Bind( + bound_fn.Run(base::Bind(&RunOnTaskRunner, task_runner_, base::Bind( &SerialRunner::RunNextInSeries, weak_this_.GetWeakPtr()))); } diff --git a/media/base/serial_runner.h b/media/base/serial_runner.h index eaae625..44300dc 100644 --- a/media/base/serial_runner.h +++ b/media/base/serial_runner.h @@ -15,7 +15,7 @@ #include "media/base/pipeline_status.h" namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; } namespace media { @@ -72,7 +72,7 @@ class MEDIA_EXPORT SerialRunner { void RunNextInSeries(PipelineStatus last_status); base::WeakPtrFactory<SerialRunner> weak_this_; - scoped_refptr<base::MessageLoopProxy> message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; Queue bound_fns_; PipelineStatusCB done_cb_; diff --git a/media/base/text_renderer.cc b/media/base/text_renderer.cc index 91f9a33..cee6fd9 100644 --- a/media/base/text_renderer.cc +++ b/media/base/text_renderer.cc @@ -7,7 +7,7 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/logging.h" -#include "base/message_loop/message_loop_proxy.h" +#include "base/single_thread_task_runner.h" #include "base/stl_util.h" #include "media/base/bind_to_loop.h" #include "media/base/decoder_buffer.h" @@ -18,9 +18,9 @@ namespace media { TextRenderer::TextRenderer( - const scoped_refptr<base::MessageLoopProxy>& message_loop, + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, const AddTextTrackCB& add_text_track_cb) - : message_loop_(message_loop), + : task_runner_(task_runner), weak_factory_(this), add_text_track_cb_(add_text_track_cb), state_(kUninitialized), @@ -35,7 +35,7 @@ TextRenderer::~TextRenderer() { } void TextRenderer::Initialize(const base::Closure& ended_cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(!ended_cb.is_null()); DCHECK_EQ(kUninitialized, state_) << "state_ " << state_; DCHECK(text_track_state_map_.empty()); @@ -49,7 +49,7 @@ void TextRenderer::Initialize(const base::Closure& ended_cb) { } void TextRenderer::Play(const base::Closure& callback) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kPaused) << "state_ " << state_; for (TextTrackStateMap::iterator itr = text_track_state_map_.begin(); @@ -68,7 +68,7 @@ void TextRenderer::Play(const base::Closure& callback) { } void TextRenderer::Pause(const base::Closure& callback) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(state_ == kPlaying || state_ == kEnded) << "state_ " << state_; DCHECK_GE(pending_read_count_, 0); pause_cb_ = callback; @@ -83,7 +83,7 @@ void TextRenderer::Pause(const base::Closure& callback) { } void TextRenderer::Flush(const base::Closure& callback) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_EQ(pending_read_count_, 0); DCHECK(state_ == kPaused) << "state_ " << state_; @@ -96,7 +96,7 @@ void TextRenderer::Flush(const base::Closure& callback) { } void TextRenderer::Stop(const base::Closure& cb) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(!cb.is_null()); DCHECK(state_ == kPlaying || state_ == kPausePending || @@ -117,7 +117,7 @@ void TextRenderer::Stop(const base::Closure& cb) { void TextRenderer::AddTextStream(DemuxerStream* text_stream, const TextTrackConfig& config) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(state_ != kUninitialized) << "state_ " << state_; DCHECK_NE(state_, kStopPending); DCHECK_NE(state_, kStopped); @@ -127,7 +127,7 @@ void TextRenderer::AddTextStream(DemuxerStream* text_stream, pending_eos_set_.end()); media::AddTextTrackDoneCB done_cb = - media::BindToLoop(message_loop_, + media::BindToLoop(task_runner_, base::Bind(&TextRenderer::OnAddTextTrackDone, weak_this_, text_stream)); @@ -136,7 +136,7 @@ void TextRenderer::AddTextStream(DemuxerStream* text_stream, } void TextRenderer::RemoveTextStream(DemuxerStream* text_stream) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); TextTrackStateMap::iterator itr = text_track_state_map_.find(text_stream); DCHECK(itr != text_track_state_map_.end()); @@ -150,7 +150,7 @@ void TextRenderer::RemoveTextStream(DemuxerStream* text_stream) { } bool TextRenderer::HasTracks() const { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); return !text_track_state_map_.empty(); } @@ -158,7 +158,7 @@ void TextRenderer::BufferReady( DemuxerStream* stream, DemuxerStream::Status status, const scoped_refptr<DecoderBuffer>& input) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK_NE(status, DemuxerStream::kConfigChanged); if (status == DemuxerStream::kAborted) { @@ -241,7 +241,7 @@ void TextRenderer::BufferReady( void TextRenderer::CueReady( DemuxerStream* text_stream, const scoped_refptr<TextCue>& text_cue) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(state_ != kUninitialized && state_ != kStopped) << "state_ " << state_; DCHECK_GT(pending_read_count_, 0); @@ -330,7 +330,7 @@ void TextRenderer::CueReady( void TextRenderer::OnAddTextTrackDone(DemuxerStream* text_stream, scoped_ptr<TextTrack> text_track) { - DCHECK(message_loop_->BelongsToCurrentThread()); + DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(state_ != kUninitialized && state_ != kStopped && state_ != kStopPending) << "state_ " << state_; diff --git a/media/base/text_renderer.h b/media/base/text_renderer.h index 532a1fa..3916ef6 100644 --- a/media/base/text_renderer.h +++ b/media/base/text_renderer.h @@ -17,7 +17,7 @@ #include "media/base/text_track.h" namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; } namespace media { @@ -30,12 +30,13 @@ class TextTrackConfig; // demuxer text stream. class MEDIA_EXPORT TextRenderer { public: - // |message_loop| is the thread on which TextRenderer will execute. + // |task_runner| is the thread on which TextRenderer will execute. // // |add_text_track_cb] is called when the demuxer requests (via its host) // that a new text track be created. - TextRenderer(const scoped_refptr<base::MessageLoopProxy>& message_loop, - const AddTextTrackCB& add_text_track_cb); + TextRenderer( + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, + const AddTextTrackCB& add_text_track_cb); ~TextRenderer(); // |ended_cb| is executed when all of the text tracks have reached @@ -101,7 +102,7 @@ class MEDIA_EXPORT TextRenderer { // Utility function to post a read request on |text_stream|. void Read(TextTrackState* state, DemuxerStream* text_stream); - scoped_refptr<base::MessageLoopProxy> message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; base::WeakPtrFactory<TextRenderer> weak_factory_; base::WeakPtr<TextRenderer> weak_this_; const AddTextTrackCB add_text_track_cb_; |