| 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 bf520a52bdb5fc81b7afcf2b77e489dd93aa1fc0..bf83407094f07f71060824a96ee010d0b7626804 100644
|
| --- a/content/common/gpu/media/v4l2_video_decode_accelerator.cc
|
| +++ b/content/common/gpu/media/v4l2_video_decode_accelerator.cc
|
| @@ -15,6 +15,7 @@
|
| #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/trace_event/trace_event.h"
|
| #include "content/common/gpu/media/v4l2_video_decode_accelerator.h"
|
| @@ -64,13 +65,13 @@
|
| struct V4L2VideoDecodeAccelerator::BitstreamBufferRef {
|
| BitstreamBufferRef(
|
| base::WeakPtr<Client>& client,
|
| - scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner,
|
| + scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy,
|
| base::SharedMemory* shm,
|
| size_t size,
|
| int32 input_id);
|
| ~BitstreamBufferRef();
|
| const base::WeakPtr<Client> client;
|
| - const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner;
|
| + const scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy;
|
| const scoped_ptr<base::SharedMemory> shm;
|
| const size_t size;
|
| size_t bytes_used;
|
| @@ -93,12 +94,10 @@
|
|
|
| V4L2VideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef(
|
| base::WeakPtr<Client>& client,
|
| - scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner,
|
| - base::SharedMemory* shm,
|
| - size_t size,
|
| - int32 input_id)
|
| + scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy,
|
| + base::SharedMemory* shm, size_t size, int32 input_id)
|
| : client(client),
|
| - client_task_runner(client_task_runner),
|
| + client_message_loop_proxy(client_message_loop_proxy),
|
| shm(shm),
|
| size(size),
|
| bytes_used(0),
|
| @@ -107,9 +106,8 @@
|
|
|
| V4L2VideoDecodeAccelerator::BitstreamBufferRef::~BitstreamBufferRef() {
|
| if (input_id >= 0) {
|
| - client_task_runner->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&Client::NotifyEndOfBitstreamBuffer, client, input_id));
|
| + client_message_loop_proxy->PostTask(FROM_HERE, base::Bind(
|
| + &Client::NotifyEndOfBitstreamBuffer, client, input_id));
|
| }
|
| }
|
|
|
| @@ -162,9 +160,9 @@
|
| const base::WeakPtr<Client>& io_client,
|
| const base::Callback<bool(void)>& make_context_current,
|
| const scoped_refptr<V4L2Device>& device,
|
| - const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
|
| - : child_task_runner_(base::ThreadTaskRunnerHandle::Get()),
|
| - io_task_runner_(io_task_runner),
|
| + const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy)
|
| + : child_message_loop_proxy_(base::MessageLoopProxy::current()),
|
| + io_message_loop_proxy_(io_message_loop_proxy),
|
| io_client_(io_client),
|
| decoder_thread_("V4L2DecoderThread"),
|
| decoder_state_(kUninitialized),
|
| @@ -211,7 +209,7 @@
|
| bool V4L2VideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
|
| Client* client) {
|
| DVLOG(3) << "Initialize()";
|
| - DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| DCHECK_EQ(decoder_state_, kUninitialized);
|
|
|
| client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client));
|
| @@ -309,7 +307,7 @@
|
| const media::BitstreamBuffer& bitstream_buffer) {
|
| DVLOG(1) << "Decode(): input_id=" << bitstream_buffer.id()
|
| << ", size=" << bitstream_buffer.size();
|
| - DCHECK(io_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
|
|
|
| // DecodeTask() will take care of running a DecodeBufferTask().
|
| decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
|
| @@ -320,7 +318,7 @@
|
| void V4L2VideoDecodeAccelerator::AssignPictureBuffers(
|
| const std::vector<media::PictureBuffer>& buffers) {
|
| DVLOG(3) << "AssignPictureBuffers(): buffer_count=" << buffers.size();
|
| - DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
|
|
| if (buffers.size() != output_buffer_map_.size()) {
|
| LOG(ERROR) << "AssignPictureBuffers(): Failed to provide requested picture"
|
| @@ -381,7 +379,7 @@
|
| 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_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
|
|
| if (!make_context_current_.Run()) {
|
| LOG(ERROR) << "ReusePictureBuffer(): could not make context current";
|
| @@ -409,21 +407,21 @@
|
|
|
| void V4L2VideoDecodeAccelerator::Flush() {
|
| DVLOG(3) << "Flush()";
|
| - DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
|
| &V4L2VideoDecodeAccelerator::FlushTask, base::Unretained(this)));
|
| }
|
|
|
| void V4L2VideoDecodeAccelerator::Reset() {
|
| DVLOG(3) << "Reset()";
|
| - DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind(
|
| &V4L2VideoDecodeAccelerator::ResetTask, base::Unretained(this)));
|
| }
|
|
|
| void V4L2VideoDecodeAccelerator::Destroy() {
|
| DVLOG(3) << "Destroy()";
|
| - DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
|
|
| // We're destroying; cancel all callbacks.
|
| client_ptr_factory_.reset();
|
| @@ -468,7 +466,7 @@
|
| bitstream_buffer.id());
|
|
|
| scoped_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef(
|
| - io_client_, io_task_runner_,
|
| + io_client_, io_message_loop_proxy_,
|
| new base::SharedMemory(bitstream_buffer.handle(), true),
|
| bitstream_buffer.size(), bitstream_buffer.id()));
|
| if (!bitstream_record->shm->Map(bitstream_buffer.size())) {
|
| @@ -1245,8 +1243,8 @@
|
| if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) {
|
| // There's nothing in the pipe, so return done immediately.
|
| DVLOG(3) << "FlushTask(): returning flush";
|
| - child_task_runner_->PostTask(FROM_HERE,
|
| - base::Bind(&Client::NotifyFlushDone, client_));
|
| + child_message_loop_proxy_->PostTask(
|
| + FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_));
|
| return;
|
| } else if (decoder_state_ == kError) {
|
| DVLOG(2) << "FlushTask(): early out: kError state";
|
| @@ -1259,7 +1257,7 @@
|
| // Queue up an empty buffer -- this triggers the flush.
|
| decoder_input_queue_.push(
|
| linked_ptr<BitstreamBufferRef>(new BitstreamBufferRef(
|
| - io_client_, io_task_runner_, NULL, 0, kFlushBufferId)));
|
| + io_client_, io_message_loop_proxy_, NULL, 0, kFlushBufferId)));
|
| decoder_flushing_ = true;
|
| SendPictureReady(); // Send all pending PictureReady.
|
|
|
| @@ -1303,8 +1301,8 @@
|
| decoder_delay_bitstream_buffer_id_ = -1;
|
| decoder_flushing_ = false;
|
| DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush";
|
| - child_task_runner_->PostTask(FROM_HERE,
|
| - base::Bind(&Client::NotifyFlushDone, client_));
|
| + child_message_loop_proxy_->PostTask(
|
| + FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_));
|
|
|
| // While we were flushing, we early-outed DecodeBufferTask()s.
|
| ScheduleDecodeBufferTaskIfNeeded();
|
| @@ -1390,8 +1388,8 @@
|
|
|
| decoder_partial_frame_pending_ = false;
|
| decoder_delay_bitstream_buffer_id_ = -1;
|
| - child_task_runner_->PostTask(FROM_HERE,
|
| - base::Bind(&Client::NotifyResetDone, client_));
|
| + child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
|
| + &Client::NotifyResetDone, client_));
|
|
|
| // While we were resetting, we early-outed DecodeBufferTask()s.
|
| ScheduleDecodeBufferTaskIfNeeded();
|
| @@ -1526,10 +1524,9 @@
|
|
|
| // Post a task to clean up buffers on child thread. This will also ensure
|
| // that we won't accept ReusePictureBuffer() anymore after that.
|
| - child_task_runner_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers,
|
| - weak_this_));
|
| + child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
|
| + &V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers,
|
| + weak_this_));
|
| }
|
|
|
| void V4L2VideoDecodeAccelerator::FinishResolutionChange() {
|
| @@ -1595,10 +1592,9 @@
|
| void V4L2VideoDecodeAccelerator::NotifyError(Error error) {
|
| DVLOG(2) << "NotifyError()";
|
|
|
| - if (!child_task_runner_->BelongsToCurrentThread()) {
|
| - child_task_runner_->PostTask(
|
| - FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::NotifyError,
|
| - weak_this_, error));
|
| + if (!child_message_loop_proxy_->BelongsToCurrentThread()) {
|
| + child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind(
|
| + &V4L2VideoDecodeAccelerator::NotifyError, weak_this_, error));
|
| return;
|
| }
|
|
|
| @@ -1845,10 +1841,12 @@
|
| DVLOG(3) << "CreateOutputBuffers(): ProvidePictureBuffers(): "
|
| << "buffer_count=" << output_buffer_map_.size()
|
| << ", coded_size=" << coded_size_.ToString();
|
| - child_task_runner_->PostTask(
|
| - FROM_HERE, base::Bind(&Client::ProvidePictureBuffers, client_,
|
| - output_buffer_map_.size(), coded_size_,
|
| - device_->GetTextureTarget()));
|
| + child_message_loop_proxy_->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
|
| @@ -1871,7 +1869,7 @@
|
|
|
| void V4L2VideoDecodeAccelerator::DestroyInputBuffers() {
|
| DVLOG(3) << "DestroyInputBuffers()";
|
| - DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| DCHECK(!input_streamon_);
|
|
|
| for (size_t i = 0; i < input_buffer_map_.size(); ++i) {
|
| @@ -1894,7 +1892,7 @@
|
|
|
| bool V4L2VideoDecodeAccelerator::DestroyOutputBuffers() {
|
| DVLOG(3) << "DestroyOutputBuffers()";
|
| - DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| DCHECK(!output_streamon_);
|
| bool success = true;
|
|
|
| @@ -1918,9 +1916,10 @@
|
|
|
| DVLOG(1) << "DestroyOutputBuffers(): dismissing PictureBuffer id="
|
| << output_record.picture_id;
|
| - child_task_runner_->PostTask(
|
| - FROM_HERE, base::Bind(&Client::DismissPictureBuffer, client_,
|
| - output_record.picture_id));
|
| + child_message_loop_proxy_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(
|
| + &Client::DismissPictureBuffer, client_, output_record.picture_id));
|
| }
|
|
|
| struct v4l2_requestbuffers reqbufs;
|
| @@ -1941,7 +1940,7 @@
|
| }
|
|
|
| void V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers() {
|
| - DCHECK(child_task_runner_->BelongsToCurrentThread());
|
| + DCHECK(child_message_loop_proxy_->BelongsToCurrentThread());
|
| DVLOG(3) << "ResolutionChangeDestroyBuffers()";
|
|
|
| if (!DestroyOutputBuffers()) {
|
| @@ -1967,7 +1966,7 @@
|
| 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_task_runner_->PostTask(
|
| + io_message_loop_proxy_->PostTask(
|
| FROM_HERE, base::Bind(&Client::PictureReady, io_client_, picture));
|
| pending_picture_ready_.pop();
|
| } else if (!cleared || resetting_or_flushing) {
|
| @@ -1980,8 +1979,9 @@
|
| // 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_task_runner_->PostTaskAndReply(
|
| - FROM_HERE, base::Bind(&Client::PictureReady, client_, picture),
|
| + child_message_loop_proxy_->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,
|
|
|