| Index: content/common/gpu/media/v4l2_video_decode_accelerator.cc
|
| diff --git a/content/common/gpu/media/v4l2_video_decode_accelerator.cc b/content/common/gpu/media/v4l2_video_decode_accelerator.cc
|
| index bf83407094f07f71060824a96ee010d0b7626804..dfd0866e47d77748e1eb6cb95a695d27c5a6c9e4 100644
|
| --- a/content/common/gpu/media/v4l2_video_decode_accelerator.cc
|
| +++ b/content/common/gpu/media/v4l2_video_decode_accelerator.cc
|
| @@ -15,8 +15,8 @@
|
| #include "base/command_line.h"
|
| #include "base/memory/shared_memory.h"
|
| #include "base/message_loop/message_loop.h"
|
| -#include "base/message_loop/message_loop_proxy.h"
|
| #include "base/numerics/safe_conversions.h"
|
| +#include "base/thread_task_runner_handle.h"
|
| #include "base/trace_event/trace_event.h"
|
| #include "content/common/gpu/media/v4l2_video_decode_accelerator.h"
|
| #include "media/base/media_switches.h"
|
| @@ -65,13 +65,13 @@ namespace {
|
| struct V4L2VideoDecodeAccelerator::BitstreamBufferRef {
|
| BitstreamBufferRef(
|
| base::WeakPtr<Client>& client,
|
| - scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy,
|
| + scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner,
|
| base::SharedMemory* shm,
|
| size_t size,
|
| int32 input_id);
|
| ~BitstreamBufferRef();
|
| const base::WeakPtr<Client> client;
|
| - const scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy;
|
| + const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner;
|
| const scoped_ptr<base::SharedMemory> shm;
|
| const size_t size;
|
| size_t bytes_used;
|
| @@ -94,10 +94,12 @@ struct V4L2VideoDecodeAccelerator::PictureRecord {
|
|
|
| V4L2VideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef(
|
| base::WeakPtr<Client>& client,
|
| - scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy,
|
| - base::SharedMemory* shm, size_t size, int32 input_id)
|
| + scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner,
|
| + base::SharedMemory* shm,
|
| + size_t size,
|
| + int32 input_id)
|
| : client(client),
|
| - client_message_loop_proxy(client_message_loop_proxy),
|
| + client_task_runner(client_task_runner),
|
| shm(shm),
|
| size(size),
|
| bytes_used(0),
|
| @@ -106,8 +108,9 @@ V4L2VideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef(
|
|
|
| V4L2VideoDecodeAccelerator::BitstreamBufferRef::~BitstreamBufferRef() {
|
| if (input_id >= 0) {
|
| - client_message_loop_proxy->PostTask(FROM_HERE, base::Bind(
|
| - &Client::NotifyEndOfBitstreamBuffer, client, input_id));
|
| + client_task_runner->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&Client::NotifyEndOfBitstreamBuffer, client, input_id));
|
| }
|
| }
|
|
|
| @@ -160,9 +163,9 @@ V4L2VideoDecodeAccelerator::V4L2VideoDecodeAccelerator(
|
| const base::WeakPtr<Client>& io_client,
|
| const base::Callback<bool(void)>& make_context_current,
|
| const scoped_refptr<V4L2Device>& device,
|
| - const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy)
|
| - : child_message_loop_proxy_(base::MessageLoopProxy::current()),
|
| - io_message_loop_proxy_(io_message_loop_proxy),
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
|
| + : child_task_runner_(base::ThreadTaskRunnerHandle::Get()),
|
| + io_task_runner_(io_task_runner),
|
| io_client_(io_client),
|
| decoder_thread_("V4L2DecoderThread"),
|
| decoder_state_(kUninitialized),
|
| @@ -209,7 +212,7 @@ V4L2VideoDecodeAccelerator::~V4L2VideoDecodeAccelerator() {
|
| bool V4L2VideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
|
| Client* client) {
|
| DVLOG(3) << "Initialize()";
|
| - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| + DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| DCHECK_EQ(decoder_state_, kUninitialized);
|
|
|
| client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client));
|
| @@ -307,7 +310,7 @@ void V4L2VideoDecodeAccelerator::Decode(
|
| const media::BitstreamBuffer& bitstream_buffer) {
|
| DVLOG(1) << "Decode(): input_id=" << bitstream_buffer.id()
|
| << ", size=" << bitstream_buffer.size();
|
| - DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
|
| + DCHECK(io_task_runner_->BelongsToCurrentThread());
|
|
|
| // DecodeTask() will take care of running a DecodeBufferTask().
|
| decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
|
| @@ -318,7 +321,7 @@ void V4L2VideoDecodeAccelerator::Decode(
|
| void V4L2VideoDecodeAccelerator::AssignPictureBuffers(
|
| const std::vector<media::PictureBuffer>& buffers) {
|
| DVLOG(3) << "AssignPictureBuffers(): buffer_count=" << buffers.size();
|
| - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| + DCHECK(child_task_runner_->BelongsToCurrentThread());
|
|
|
| if (buffers.size() != output_buffer_map_.size()) {
|
| LOG(ERROR) << "AssignPictureBuffers(): Failed to provide requested picture"
|
| @@ -379,7 +382,7 @@ void V4L2VideoDecodeAccelerator::AssignPictureBuffers(
|
| void V4L2VideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) {
|
| DVLOG(3) << "ReusePictureBuffer(): picture_buffer_id=" << picture_buffer_id;
|
| // Must be run on child thread, as we'll insert a sync in the EGL context.
|
| - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| + DCHECK(child_task_runner_->BelongsToCurrentThread());
|
|
|
| if (!make_context_current_.Run()) {
|
| LOG(ERROR) << "ReusePictureBuffer(): could not make context current";
|
| @@ -407,21 +410,21 @@ void V4L2VideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) {
|
|
|
| void V4L2VideoDecodeAccelerator::Flush() {
|
| DVLOG(3) << "Flush()";
|
| - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| + DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
|
| &V4L2VideoDecodeAccelerator::FlushTask, base::Unretained(this)));
|
| }
|
|
|
| void V4L2VideoDecodeAccelerator::Reset() {
|
| DVLOG(3) << "Reset()";
|
| - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| + DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
|
| &V4L2VideoDecodeAccelerator::ResetTask, base::Unretained(this)));
|
| }
|
|
|
| void V4L2VideoDecodeAccelerator::Destroy() {
|
| DVLOG(3) << "Destroy()";
|
| - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| + DCHECK(child_task_runner_->BelongsToCurrentThread());
|
|
|
| // We're destroying; cancel all callbacks.
|
| client_ptr_factory_.reset();
|
| @@ -466,7 +469,7 @@ void V4L2VideoDecodeAccelerator::DecodeTask(
|
| bitstream_buffer.id());
|
|
|
| scoped_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef(
|
| - io_client_, io_message_loop_proxy_,
|
| + io_client_, io_task_runner_,
|
| new base::SharedMemory(bitstream_buffer.handle(), true),
|
| bitstream_buffer.size(), bitstream_buffer.id()));
|
| if (!bitstream_record->shm->Map(bitstream_buffer.size())) {
|
| @@ -1243,8 +1246,8 @@ void V4L2VideoDecodeAccelerator::FlushTask() {
|
| if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) {
|
| // There's nothing in the pipe, so return done immediately.
|
| DVLOG(3) << "FlushTask(): returning flush";
|
| - child_message_loop_proxy_->PostTask(
|
| - FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_));
|
| + child_task_runner_->PostTask(FROM_HERE,
|
| + base::Bind(&Client::NotifyFlushDone, client_));
|
| return;
|
| } else if (decoder_state_ == kError) {
|
| DVLOG(2) << "FlushTask(): early out: kError state";
|
| @@ -1257,7 +1260,7 @@ void V4L2VideoDecodeAccelerator::FlushTask() {
|
| // Queue up an empty buffer -- this triggers the flush.
|
| decoder_input_queue_.push(
|
| linked_ptr<BitstreamBufferRef>(new BitstreamBufferRef(
|
| - io_client_, io_message_loop_proxy_, NULL, 0, kFlushBufferId)));
|
| + io_client_, io_task_runner_, NULL, 0, kFlushBufferId)));
|
| decoder_flushing_ = true;
|
| SendPictureReady(); // Send all pending PictureReady.
|
|
|
| @@ -1301,8 +1304,8 @@ void V4L2VideoDecodeAccelerator::NotifyFlushDoneIfNeeded() {
|
| decoder_delay_bitstream_buffer_id_ = -1;
|
| decoder_flushing_ = false;
|
| DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush";
|
| - child_message_loop_proxy_->PostTask(
|
| - FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_));
|
| + child_task_runner_->PostTask(FROM_HERE,
|
| + base::Bind(&Client::NotifyFlushDone, client_));
|
|
|
| // While we were flushing, we early-outed DecodeBufferTask()s.
|
| ScheduleDecodeBufferTaskIfNeeded();
|
| @@ -1388,8 +1391,8 @@ void V4L2VideoDecodeAccelerator::ResetDoneTask() {
|
|
|
| decoder_partial_frame_pending_ = false;
|
| decoder_delay_bitstream_buffer_id_ = -1;
|
| - child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
|
| - &Client::NotifyResetDone, client_));
|
| + child_task_runner_->PostTask(FROM_HERE,
|
| + base::Bind(&Client::NotifyResetDone, client_));
|
|
|
| // While we were resetting, we early-outed DecodeBufferTask()s.
|
| ScheduleDecodeBufferTaskIfNeeded();
|
| @@ -1524,9 +1527,10 @@ void V4L2VideoDecodeAccelerator::StartResolutionChangeIfNeeded() {
|
|
|
| // Post a task to clean up buffers on child thread. This will also ensure
|
| // that we won't accept ReusePictureBuffer() anymore after that.
|
| - child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
|
| - &V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers,
|
| - weak_this_));
|
| + child_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers,
|
| + weak_this_));
|
| }
|
|
|
| void V4L2VideoDecodeAccelerator::FinishResolutionChange() {
|
| @@ -1592,9 +1596,10 @@ void V4L2VideoDecodeAccelerator::DevicePollTask(bool poll_device) {
|
| void V4L2VideoDecodeAccelerator::NotifyError(Error error) {
|
| DVLOG(2) << "NotifyError()";
|
|
|
| - if (!child_message_loop_proxy_->BelongsToCurrentThread()) {
|
| - child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
|
| - &V4L2VideoDecodeAccelerator::NotifyError, weak_this_, error));
|
| + if (!child_task_runner_->BelongsToCurrentThread()) {
|
| + child_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::NotifyError,
|
| + weak_this_, error));
|
| return;
|
| }
|
|
|
| @@ -1841,12 +1846,10 @@ bool V4L2VideoDecodeAccelerator::CreateOutputBuffers() {
|
| DVLOG(3) << "CreateOutputBuffers(): ProvidePictureBuffers(): "
|
| << "buffer_count=" << output_buffer_map_.size()
|
| << ", coded_size=" << coded_size_.ToString();
|
| - child_message_loop_proxy_->PostTask(FROM_HERE,
|
| - base::Bind(&Client::ProvidePictureBuffers,
|
| - client_,
|
| - output_buffer_map_.size(),
|
| - coded_size_,
|
| - device_->GetTextureTarget()));
|
| + child_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&Client::ProvidePictureBuffers, client_,
|
| + output_buffer_map_.size(), coded_size_,
|
| + device_->GetTextureTarget()));
|
|
|
| // Wait for the client to call AssignPictureBuffers() on the Child thread.
|
| // We do this, because if we continue decoding without finishing buffer
|
| @@ -1869,7 +1872,7 @@ bool V4L2VideoDecodeAccelerator::CreateOutputBuffers() {
|
|
|
| void V4L2VideoDecodeAccelerator::DestroyInputBuffers() {
|
| DVLOG(3) << "DestroyInputBuffers()";
|
| - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| + DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| DCHECK(!input_streamon_);
|
|
|
| for (size_t i = 0; i < input_buffer_map_.size(); ++i) {
|
| @@ -1892,7 +1895,7 @@ void V4L2VideoDecodeAccelerator::DestroyInputBuffers() {
|
|
|
| bool V4L2VideoDecodeAccelerator::DestroyOutputBuffers() {
|
| DVLOG(3) << "DestroyOutputBuffers()";
|
| - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| + DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| DCHECK(!output_streamon_);
|
| bool success = true;
|
|
|
| @@ -1916,10 +1919,9 @@ bool V4L2VideoDecodeAccelerator::DestroyOutputBuffers() {
|
|
|
| DVLOG(1) << "DestroyOutputBuffers(): dismissing PictureBuffer id="
|
| << output_record.picture_id;
|
| - child_message_loop_proxy_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(
|
| - &Client::DismissPictureBuffer, client_, output_record.picture_id));
|
| + child_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&Client::DismissPictureBuffer, client_,
|
| + output_record.picture_id));
|
| }
|
|
|
| struct v4l2_requestbuffers reqbufs;
|
| @@ -1940,7 +1942,7 @@ bool V4L2VideoDecodeAccelerator::DestroyOutputBuffers() {
|
| }
|
|
|
| void V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers() {
|
| - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| + DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| DVLOG(3) << "ResolutionChangeDestroyBuffers()";
|
|
|
| if (!DestroyOutputBuffers()) {
|
| @@ -1966,7 +1968,7 @@ void V4L2VideoDecodeAccelerator::SendPictureReady() {
|
| if (cleared && picture_clearing_count_ == 0) {
|
| // This picture is cleared. Post it to IO thread to reduce latency. This
|
| // should be the case after all pictures are cleared at the beginning.
|
| - io_message_loop_proxy_->PostTask(
|
| + io_task_runner_->PostTask(
|
| FROM_HERE, base::Bind(&Client::PictureReady, io_client_, picture));
|
| pending_picture_ready_.pop();
|
| } else if (!cleared || resetting_or_flushing) {
|
| @@ -1979,9 +1981,8 @@ void V4L2VideoDecodeAccelerator::SendPictureReady() {
|
| // has to be cleared in the child thread. A picture only needs to be
|
| // cleared once. If the decoder is resetting or flushing, send all
|
| // pictures to ensure PictureReady arrive before reset or flush done.
|
| - child_message_loop_proxy_->PostTaskAndReply(
|
| - FROM_HERE,
|
| - base::Bind(&Client::PictureReady, client_, picture),
|
| + child_task_runner_->PostTaskAndReply(
|
| + FROM_HERE, base::Bind(&Client::PictureReady, client_, picture),
|
| // Unretained is safe. If Client::PictureReady gets to run, |this| is
|
| // alive. Destroy() will wait the decode thread to finish.
|
| base::Bind(&V4L2VideoDecodeAccelerator::PictureCleared,
|
|
|