Index: media/filters/gpu_video_decoder.cc |
diff --git a/media/filters/gpu_video_decoder.cc b/media/filters/gpu_video_decoder.cc |
index 940bec1c52dc7c9a518590682fc5ce5e3f91402d..16619b240197d11c92e7b73a8cbd3d745817fc2b 100644 |
--- a/media/filters/gpu_video_decoder.cc |
+++ b/media/filters/gpu_video_decoder.cc |
@@ -20,112 +20,6 @@ |
namespace media { |
-// Proxies calls to a VideoDecodeAccelerator::Client from the calling thread to |
Ami GONE FROM CHROMIUM
2013/07/22 19:46:21
This makes me ever so happy!
|
-// the client's thread. |
-// |
-// TODO(scherkus): VDAClientProxy should hold onto GpuVideoDecoder::Factories |
-// and take care of some of the work that GpuVideoDecoder does to minimize |
-// thread hopping. See following for discussion: |
-// |
-// https://codereview.chromium.org/12989009/diff/27035/media/filters/gpu_video_decoder.cc#newcode23 |
-class VDAClientProxy |
- : public base::RefCountedThreadSafe<VDAClientProxy>, |
- public VideoDecodeAccelerator::Client { |
- public: |
- explicit VDAClientProxy(VideoDecodeAccelerator::Client* client); |
- |
- // Detaches the proxy. |weak_client_| will no longer be called and can be |
- // safely deleted. Any pending/future calls will be discarded. |
- // |
- // Must be called on |client_loop_|. |
- void Detach(); |
- |
- // VideoDecodeAccelerator::Client implementation. |
- virtual void NotifyInitializeDone() OVERRIDE; |
- virtual void ProvidePictureBuffers(uint32 count, |
- const gfx::Size& size, |
- uint32 texture_target) OVERRIDE; |
- virtual void DismissPictureBuffer(int32 id) OVERRIDE; |
- virtual void PictureReady(const media::Picture& picture) OVERRIDE; |
- virtual void NotifyEndOfBitstreamBuffer(int32 id) OVERRIDE; |
- virtual void NotifyFlushDone() OVERRIDE; |
- virtual void NotifyResetDone() OVERRIDE; |
- virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE; |
- |
- private: |
- friend class base::RefCountedThreadSafe<VDAClientProxy>; |
- virtual ~VDAClientProxy(); |
- |
- scoped_refptr<base::MessageLoopProxy> client_loop_; |
- |
- // Weak pointers are used to invalidate tasks posted to |client_loop_| after |
- // Detach() has been called. |
- base::WeakPtrFactory<VideoDecodeAccelerator::Client> weak_client_factory_; |
- base::WeakPtr<VideoDecodeAccelerator::Client> weak_client_; |
- |
- DISALLOW_COPY_AND_ASSIGN(VDAClientProxy); |
-}; |
- |
-VDAClientProxy::VDAClientProxy(VideoDecodeAccelerator::Client* client) |
- : client_loop_(base::MessageLoopProxy::current()), |
- weak_client_factory_(client), |
- weak_client_(weak_client_factory_.GetWeakPtr()) { |
- DCHECK(weak_client_.get()); |
-} |
- |
-VDAClientProxy::~VDAClientProxy() {} |
- |
-void VDAClientProxy::Detach() { |
- DCHECK(client_loop_->BelongsToCurrentThread()); |
- DCHECK(weak_client_.get()) << "Detach() already called"; |
- weak_client_factory_.InvalidateWeakPtrs(); |
-} |
- |
-void VDAClientProxy::NotifyInitializeDone() { |
- client_loop_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Client::NotifyInitializeDone, weak_client_)); |
-} |
- |
-void VDAClientProxy::ProvidePictureBuffers(uint32 count, |
- const gfx::Size& size, |
- uint32 texture_target) { |
- client_loop_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Client::ProvidePictureBuffers, weak_client_, |
- count, size, texture_target)); |
-} |
- |
-void VDAClientProxy::DismissPictureBuffer(int32 id) { |
- client_loop_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Client::DismissPictureBuffer, weak_client_, id)); |
-} |
- |
-void VDAClientProxy::PictureReady(const media::Picture& picture) { |
- client_loop_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Client::PictureReady, weak_client_, picture)); |
-} |
- |
-void VDAClientProxy::NotifyEndOfBitstreamBuffer(int32 id) { |
- client_loop_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Client::NotifyEndOfBitstreamBuffer, weak_client_, |
- id)); |
-} |
- |
-void VDAClientProxy::NotifyFlushDone() { |
- client_loop_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Client::NotifyFlushDone, weak_client_)); |
-} |
- |
-void VDAClientProxy::NotifyResetDone() { |
- client_loop_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Client::NotifyResetDone, weak_client_)); |
-} |
- |
-void VDAClientProxy::NotifyError(media::VideoDecodeAccelerator::Error error) { |
- client_loop_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Client::NotifyError, weak_client_, error)); |
-} |
- |
- |
// Maximum number of concurrent VDA::Decode() operations GVD will maintain. |
// Higher values allow better pipelining in the GPU, but also require more |
// resources. |
@@ -164,7 +58,6 @@ GpuVideoDecoder::GpuVideoDecoder( |
: needs_bitstream_conversion_(false), |
gvd_loop_proxy_(message_loop), |
weak_factory_(this), |
- vda_loop_proxy_(factories->GetMessageLoop()), |
factories_(factories), |
state_(kNormal), |
decoder_texture_target_(0), |
@@ -172,6 +65,7 @@ GpuVideoDecoder::GpuVideoDecoder( |
next_bitstream_buffer_id_(0), |
available_pictures_(0) { |
DCHECK(factories_.get()); |
+ DCHECK_EQ(message_loop.get(), factories->GetMessageLoop().get()); |
} |
void GpuVideoDecoder::Reset(const base::Closure& closure) { |
@@ -202,8 +96,7 @@ void GpuVideoDecoder::Reset(const base::Closure& closure) { |
DCHECK(pending_reset_cb_.is_null()); |
pending_reset_cb_ = BindToCurrentLoop(closure); |
- vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Reset, weak_vda_)); |
+ vda_->Reset(); |
} |
void GpuVideoDecoder::Stop(const base::Closure& closure) { |
@@ -259,9 +152,8 @@ void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config, |
return; |
} |
- client_proxy_ = new VDAClientProxy(this); |
- VideoDecodeAccelerator* vda = factories_->CreateVideoDecodeAccelerator( |
- config.profile(), client_proxy_.get()); |
+ VideoDecodeAccelerator* vda = |
+ factories_->CreateVideoDecodeAccelerator(config.profile(), this); |
Ami GONE FROM CHROMIUM
2013/07/22 19:46:21
nit: you don't need this intermediate variable; yo
wuchengli
2013/07/23 16:29:28
Done.
|
if (!vda) { |
status_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
return; |
@@ -271,21 +163,7 @@ void GpuVideoDecoder::Initialize(const VideoDecoderConfig& config, |
needs_bitstream_conversion_ = (config.codec() == kCodecH264); |
DVLOG(3) << "GpuVideoDecoder::Initialize() succeeded."; |
- PostTaskAndReplyWithResult( |
- vda_loop_proxy_.get(), |
- FROM_HERE, |
- base::Bind(&VideoDecodeAccelerator::AsWeakPtr, base::Unretained(vda)), |
- base::Bind(&GpuVideoDecoder::SetVDA, weak_this_, status_cb, vda)); |
-} |
- |
-void GpuVideoDecoder::SetVDA( |
- const PipelineStatusCB& status_cb, |
- VideoDecodeAccelerator* vda, |
- base::WeakPtr<VideoDecodeAccelerator> weak_vda) { |
- DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
- DCHECK(!vda_.get()); |
vda_.reset(vda); |
- weak_vda_ = weak_vda; |
status_cb.Run(PIPELINE_OK); |
} |
@@ -305,25 +183,11 @@ void GpuVideoDecoder::DestroyTextures() { |
dismissed_picture_buffers_.clear(); |
} |
-static void DestroyVDAWithClientProxy( |
- const scoped_refptr<VDAClientProxy>& client_proxy, |
- base::WeakPtr<VideoDecodeAccelerator> weak_vda) { |
- if (weak_vda.get()) { |
- weak_vda->Destroy(); |
- DCHECK(!weak_vda.get()); // Check VDA::Destroy() contract. |
- } |
-} |
- |
void GpuVideoDecoder::DestroyVDA() { |
DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
- // |client_proxy| must stay alive until |weak_vda_| has been destroyed. |
- vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
- &DestroyVDAWithClientProxy, client_proxy_, weak_vda_)); |
- |
- VideoDecodeAccelerator* vda ALLOW_UNUSED = vda_.release(); |
- client_proxy_->Detach(); |
- client_proxy_ = NULL; |
+ if (vda_) |
+ vda_.release()->Destroy(); |
DestroyTextures(); |
} |
@@ -364,8 +228,7 @@ void GpuVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
if (buffer->IsEndOfStream()) { |
if (state_ == kNormal) { |
state_ = kDrainingDecoder; |
- vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Flush, weak_vda_)); |
+ vda_->Flush(); |
} |
return; |
} |
@@ -387,8 +250,7 @@ void GpuVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, |
DCHECK(inserted); |
RecordBufferData(bitstream_buffer, *buffer.get()); |
- vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::Decode, weak_vda_, bitstream_buffer)); |
+ vda_->Decode(bitstream_buffer); |
if (!ready_video_frames_.empty()) { |
EnqueueFrameAndTriggerFrameDelivery(NULL); |
@@ -491,9 +353,7 @@ void GpuVideoDecoder::ProvidePictureBuffers(uint32 count, |
available_pictures_ += count; |
- vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::AssignPictureBuffers, weak_vda_, |
- picture_buffers)); |
+ vda_->AssignPictureBuffers(picture_buffers); |
} |
void GpuVideoDecoder::DismissPictureBuffer(int32 id) { |
@@ -620,9 +480,7 @@ void GpuVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id, |
factories_->WaitSyncPoint(sync_point); |
++available_pictures_; |
- vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
- &VideoDecodeAccelerator::ReusePictureBuffer, weak_vda_, |
- picture_buffer_id)); |
+ vda_->ReusePictureBuffer(picture_buffer_id); |
} |
GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { |