Chromium Code Reviews| Index: media/gpu/vaapi_video_decode_accelerator.cc |
| diff --git a/media/gpu/vaapi_video_decode_accelerator.cc b/media/gpu/vaapi_video_decode_accelerator.cc |
| index 06fb40fbfdfc6de1a20c64dde4f5d096c67dee42..7d361be2136aa3de20412d2a38af9434f4804d12 100644 |
| --- a/media/gpu/vaapi_video_decode_accelerator.cc |
| +++ b/media/gpu/vaapi_video_decode_accelerator.cc |
| @@ -16,6 +16,7 @@ |
| #include "base/stl_util.h" |
| #include "base/strings/string_util.h" |
| #include "base/synchronization/waitable_event.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| #include "base/trace_event/trace_event.h" |
| #include "gpu/ipc/service/gpu_channel.h" |
| #include "media/base/bind_to_current_loop.h" |
| @@ -266,16 +267,16 @@ VaapiVideoDecodeAccelerator::InputBuffer::InputBuffer() : id(0) {} |
| VaapiVideoDecodeAccelerator::InputBuffer::~InputBuffer() {} |
| void VaapiVideoDecodeAccelerator::NotifyError(Error error) { |
| - if (message_loop_ != base::MessageLoop::current()) { |
| + if (!task_runner_->BelongsToCurrentThread()) { |
| DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); |
| - message_loop_->PostTask( |
| - FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::NotifyError, |
| - weak_this_, error)); |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(&VaapiVideoDecodeAccelerator::NotifyError, |
| + weak_this_, error)); |
| return; |
| } |
| // Post Cleanup() as a task so we don't recursively acquire lock_. |
| - message_loop_->PostTask( |
| + task_runner_->PostTask( |
| FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::Cleanup, weak_this_)); |
| LOG(ERROR) << "Notifying of error " << error; |
| @@ -302,7 +303,7 @@ VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( |
| : state_(kUninitialized), |
| input_ready_(&lock_), |
| surfaces_available_(&lock_), |
| - message_loop_(base::MessageLoop::current()), |
| + task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| decoder_thread_("VaapiDecoderThread"), |
| num_frames_at_client_(0), |
| num_stream_bufs_at_decoder_(0), |
| @@ -318,12 +319,12 @@ VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( |
| } |
| VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| } |
| bool VaapiVideoDecodeAccelerator::Initialize(const Config& config, |
| Client* client) { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| if (config.is_encrypted) { |
| NOTREACHED() << "Encrypted streams are not supported for this VDA"; |
| @@ -393,7 +394,7 @@ void VaapiVideoDecodeAccelerator::OutputPicture( |
| const scoped_refptr<VASurface>& va_surface, |
| int32_t input_id, |
| VaapiPicture* picture) { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
|
chcunningham
2016/06/21 21:29:59
Missing semicolons
fdoray
2016/06/29 15:44:31
Done.
|
| int32_t output_id = picture->picture_buffer_id(); |
| @@ -421,7 +422,7 @@ void VaapiVideoDecodeAccelerator::OutputPicture( |
| } |
| void VaapiVideoDecodeAccelerator::TryOutputSurface() { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| // Handle Destroy() arriving while pictures are queued for output. |
| if (!client_) |
| @@ -445,7 +446,7 @@ void VaapiVideoDecodeAccelerator::TryOutputSurface() { |
| void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( |
| const BitstreamBuffer& bitstream_buffer) { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| TRACE_EVENT1("Video Decoder", "MapAndQueueNewInputBuffer", "input_id", |
| bitstream_buffer.id()); |
| @@ -532,7 +533,7 @@ void VaapiVideoDecodeAccelerator::ReturnCurrInputBuffer_Locked() { |
| int32_t id = curr_input_buffer_->id; |
| curr_input_buffer_.reset(); |
| DVLOG(4) << "End of input buffer " << id; |
| - message_loop_->PostTask( |
| + task_runner_->PostTask( |
| FROM_HERE, base::Bind(&Client::NotifyEndOfBitstreamBuffer, client_, id)); |
| --num_stream_bufs_at_decoder_; |
| @@ -587,7 +588,7 @@ void VaapiVideoDecodeAccelerator::DecodeTask() { |
| switch (res) { |
| case AcceleratedVideoDecoder::kAllocateNewSurfaces: |
| DVLOG(1) << "Decoder requesting a new set of surfaces"; |
| - message_loop_->PostTask( |
| + task_runner_->PostTask( |
| FROM_HERE, |
| base::Bind(&VaapiVideoDecodeAccelerator::InitiateSurfaceSetChange, |
| weak_this_, decoder_->GetRequiredNumOfPictures(), |
| @@ -617,7 +618,7 @@ void VaapiVideoDecodeAccelerator::DecodeTask() { |
| void VaapiVideoDecodeAccelerator::InitiateSurfaceSetChange(size_t num_pics, |
| gfx::Size size) { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| DCHECK(!awaiting_va_surfaces_recycle_); |
| // At this point decoder has stopped running and has already posted onto our |
| @@ -648,7 +649,7 @@ static VideoPixelFormat BufferFormatToVideoPixelFormat( |
| } |
| void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| if (!awaiting_va_surfaces_recycle_) |
| return; |
| @@ -662,7 +663,7 @@ void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { |
| // as the result, but not all have executed yet. Post ourselves after them |
| // to let them release surfaces. |
| DVLOG(2) << "Awaiting pending output/surface release callbacks to finish"; |
| - message_loop_->PostTask( |
| + task_runner_->PostTask( |
| FROM_HERE, |
| base::Bind(&VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange, |
| weak_this_)); |
| @@ -688,7 +689,7 @@ void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { |
| VideoPixelFormat format = |
| BufferFormatToVideoPixelFormat(kOutputPictureFormat); |
| - message_loop_->PostTask( |
| + task_runner_->PostTask( |
| FROM_HERE, base::Bind(&Client::ProvidePictureBuffers, client_, |
| requested_num_pics_, format, 1, requested_pic_size_, |
| VaapiPicture::GetGLTextureTarget())); |
| @@ -696,7 +697,7 @@ void VaapiVideoDecodeAccelerator::TryFinishSurfaceSetChange() { |
| void VaapiVideoDecodeAccelerator::Decode( |
| const BitstreamBuffer& bitstream_buffer) { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| TRACE_EVENT1("Video Decoder", "VAVDA::Decode", "Buffer id", |
| bitstream_buffer.id()); |
| @@ -739,7 +740,7 @@ void VaapiVideoDecodeAccelerator::Decode( |
| void VaapiVideoDecodeAccelerator::RecycleVASurfaceID( |
| VASurfaceID va_surface_id) { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| base::AutoLock auto_lock(lock_); |
| available_va_surfaces_.push_back(va_surface_id); |
| @@ -748,7 +749,7 @@ void VaapiVideoDecodeAccelerator::RecycleVASurfaceID( |
| void VaapiVideoDecodeAccelerator::AssignPictureBuffers( |
| const std::vector<PictureBuffer>& buffers) { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| base::AutoLock auto_lock(lock_); |
| DCHECK(pictures_.empty()); |
| @@ -816,7 +817,7 @@ static void CloseGpuMemoryBufferHandle( |
| void VaapiVideoDecodeAccelerator::ImportBufferForPicture( |
| int32_t picture_buffer_id, |
| const gfx::GpuMemoryBufferHandle& gpu_memory_buffer_handle) { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| DVLOG(2) << "Importing picture id: " << picture_buffer_id; |
| if (output_mode_ != Config::OutputMode::IMPORT) { |
| @@ -856,7 +857,7 @@ void VaapiVideoDecodeAccelerator::ImportBufferForPicture( |
| void VaapiVideoDecodeAccelerator::ReusePictureBuffer( |
| int32_t picture_buffer_id) { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| TRACE_EVENT1("Video Decoder", "VAVDA::ReusePictureBuffer", "Picture id", |
| picture_buffer_id); |
| @@ -880,13 +881,13 @@ void VaapiVideoDecodeAccelerator::FlushTask() { |
| // Put the decoder in idle state, ready to resume. |
| decoder_->Reset(); |
| - message_loop_->PostTask( |
| + task_runner_->PostTask( |
| FROM_HERE, |
| base::Bind(&VaapiVideoDecodeAccelerator::FinishFlush, weak_this_)); |
| } |
| void VaapiVideoDecodeAccelerator::Flush() { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| DVLOG(1) << "Got flush request"; |
| base::AutoLock auto_lock(lock_); |
| @@ -901,7 +902,7 @@ void VaapiVideoDecodeAccelerator::Flush() { |
| } |
| void VaapiVideoDecodeAccelerator::FinishFlush() { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| finish_flush_pending_ = false; |
| @@ -920,8 +921,8 @@ void VaapiVideoDecodeAccelerator::FinishFlush() { |
| state_ = kIdle; |
| - message_loop_->PostTask(FROM_HERE, |
| - base::Bind(&Client::NotifyFlushDone, client_)); |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(&Client::NotifyFlushDone, client_)); |
| DVLOG(1) << "Flush finished"; |
| } |
| @@ -942,13 +943,13 @@ void VaapiVideoDecodeAccelerator::ResetTask() { |
| ReturnCurrInputBuffer_Locked(); |
| // And let client know that we are done with reset. |
| - message_loop_->PostTask( |
| + task_runner_->PostTask( |
| FROM_HERE, |
| base::Bind(&VaapiVideoDecodeAccelerator::FinishReset, weak_this_)); |
| } |
| void VaapiVideoDecodeAccelerator::Reset() { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| DVLOG(1) << "Got reset request"; |
| // This will make any new decode tasks exit early. |
| @@ -958,7 +959,7 @@ void VaapiVideoDecodeAccelerator::Reset() { |
| // Drop all remaining input buffers, if present. |
| while (!input_buffers_.empty()) { |
| - message_loop_->PostTask( |
| + task_runner_->PostTask( |
| FROM_HERE, base::Bind(&Client::NotifyEndOfBitstreamBuffer, client_, |
| input_buffers_.front()->id)); |
| input_buffers_.pop(); |
| @@ -973,7 +974,7 @@ void VaapiVideoDecodeAccelerator::Reset() { |
| } |
| void VaapiVideoDecodeAccelerator::FinishReset() { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| DVLOG(1) << "FinishReset"; |
| base::AutoLock auto_lock(lock_); |
| @@ -990,7 +991,7 @@ void VaapiVideoDecodeAccelerator::FinishReset() { |
| // Decoder requested a new surface set while we were waiting for it to |
| // finish the last DecodeTask, running at the time of Reset(). |
| // Let the surface set change finish first before resetting. |
| - message_loop_->PostTask( |
| + task_runner_->PostTask( |
| FROM_HERE, |
| base::Bind(&VaapiVideoDecodeAccelerator::FinishReset, weak_this_)); |
| return; |
| @@ -999,8 +1000,8 @@ void VaapiVideoDecodeAccelerator::FinishReset() { |
| num_stream_bufs_at_decoder_ = 0; |
| state_ = kIdle; |
| - message_loop_->PostTask(FROM_HERE, |
| - base::Bind(&Client::NotifyResetDone, client_)); |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(&Client::NotifyResetDone, client_)); |
| // The client might have given us new buffers via Decode() while we were |
| // resetting and might be waiting for our move, and not call Decode() anymore |
| @@ -1019,7 +1020,7 @@ void VaapiVideoDecodeAccelerator::FinishReset() { |
| } |
| void VaapiVideoDecodeAccelerator::Cleanup() { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| base::AutoLock auto_lock(lock_); |
| if (state_ == kUninitialized || state_ == kDestroying) |
| @@ -1045,7 +1046,7 @@ void VaapiVideoDecodeAccelerator::Cleanup() { |
| } |
| void VaapiVideoDecodeAccelerator::Destroy() { |
| - DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
| + DCHECK(task_runner_->BelongsToCurrentThread()) |
| Cleanup(); |
| delete this; |
| } |
| @@ -1069,8 +1070,8 @@ bool VaapiVideoDecodeAccelerator::DecodeSurface( |
| void VaapiVideoDecodeAccelerator::SurfaceReady( |
| const scoped_refptr<VaapiDecodeSurface>& dec_surface) { |
| - if (message_loop_ != base::MessageLoop::current()) { |
| - message_loop_->PostTask( |
| + if (!task_runner_->BelongsToCurrentThread()) { |
| + task_runner_->PostTask( |
| FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::SurfaceReady, |
| weak_this_, dec_surface)); |
| return; |