Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1064)

Unified Diff: media/filters/gpu_video_decoder.cc

Issue 10749019: VideoDecodeAccelerator now SupportsWeakPtr instead of being RefCountedThreadSafe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/filters/gpu_video_decoder.cc
diff --git a/media/filters/gpu_video_decoder.cc b/media/filters/gpu_video_decoder.cc
index 7415db87ac0bb4b4513313a1683fbfc82ea49a8c..5f387362ec78e97ff9995cd5b316d4b438d3d353 100644
--- a/media/filters/gpu_video_decoder.cc
+++ b/media/filters/gpu_video_decoder.cc
@@ -72,7 +72,7 @@ void GpuVideoDecoder::Reset(const base::Closure& closure) {
// Throw away any already-decoded, not-yet-delivered frames.
ready_video_frames_.clear();
- if (!vda_) {
+ if (!vda_.get()) {
closure.Run();
return;
}
@@ -94,7 +94,7 @@ void GpuVideoDecoder::Reset(const base::Closure& closure) {
}
vda_loop_proxy_->PostTask(FROM_HERE, base::Bind(
- &VideoDecodeAccelerator::Reset, vda_));
+ &VideoDecodeAccelerator::Reset, weak_vda_));
}
void GpuVideoDecoder::Stop(const base::Closure& closure) {
@@ -103,13 +103,12 @@ void GpuVideoDecoder::Stop(const base::Closure& closure) {
&GpuVideoDecoder::Stop, this, closure));
return;
}
- if (!vda_) {
+ if (!vda_.get()) {
closure.Run();
return;
}
vda_loop_proxy_->PostTask(FROM_HERE, base::Bind(
- &VideoDecodeAccelerator::Destroy, vda_));
- vda_ = NULL;
+ &VideoDecodeAccelerator::Destroy, weak_vda_, base::Passed(&vda_)));
closure.Run();
}
@@ -141,8 +140,9 @@ void GpuVideoDecoder::Initialize(const scoped_refptr<DemuxerStream>& stream,
return;
}
- vda_ = factories_->CreateVideoDecodeAccelerator(config.profile(), this);
- if (!vda_) {
+ VideoDecodeAccelerator* vda =
+ factories_->CreateVideoDecodeAccelerator(config.profile(), this);
+ if (!vda) {
status_cb.Run(DECODER_ERROR_NOT_SUPPORTED);
return;
}
@@ -156,7 +156,16 @@ void GpuVideoDecoder::Initialize(const scoped_refptr<DemuxerStream>& stream,
config_frame_duration_ = GetFrameDuration(config);
DVLOG(1) << "GpuVideoDecoder::Initialize() succeeded.";
- status_cb.Run(PIPELINE_OK);
+ vda_loop_proxy_->PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(&GpuVideoDecoder::SetVDA, this, vda),
+ base::Bind(status_cb, PIPELINE_OK));
+}
+
+void GpuVideoDecoder::SetVDA(VideoDecodeAccelerator* vda) {
+ DCHECK(vda_loop_proxy_->BelongsToCurrentThread());
+ vda_.reset(vda);
+ weak_vda_ = vda->AsWeakPtr();
}
void GpuVideoDecoder::Read(const ReadCB& read_cb) {
@@ -171,7 +180,7 @@ void GpuVideoDecoder::Read(const ReadCB& read_cb) {
return;
}
- if (!vda_) {
+ if (!vda_.get()) {
read_cb.Run(kOk, VideoFrame::CreateEmptyFrame());
return;
}
@@ -218,7 +227,7 @@ void GpuVideoDecoder::RequestBufferDecode(
return;
}
- if (!vda_) {
+ if (!vda_.get()) {
EnqueueFrameAndTriggerFrameDelivery(VideoFrame::CreateEmptyFrame());
return;
}
@@ -227,7 +236,7 @@ void GpuVideoDecoder::RequestBufferDecode(
if (state_ == kNormal) {
state_ = kDrainingDecoder;
vda_loop_proxy_->PostTask(FROM_HERE, base::Bind(
- &VideoDecodeAccelerator::Flush, vda_));
+ &VideoDecodeAccelerator::Flush, weak_vda_));
}
return;
}
@@ -243,7 +252,7 @@ void GpuVideoDecoder::RequestBufferDecode(
RecordBufferTimeData(bitstream_buffer, *buffer);
vda_loop_proxy_->PostTask(FROM_HERE, base::Bind(
- &VideoDecodeAccelerator::Decode, vda_, bitstream_buffer));
+ &VideoDecodeAccelerator::Decode, weak_vda_, bitstream_buffer));
}
void GpuVideoDecoder::RecordBufferTimeData(
@@ -319,7 +328,7 @@ void GpuVideoDecoder::ProvidePictureBuffers(uint32 count,
return;
}
- if (!vda_)
+ if (!vda_.get())
return;
std::vector<PictureBuffer> picture_buffers;
@@ -331,7 +340,8 @@ void GpuVideoDecoder::ProvidePictureBuffers(uint32 count,
DCHECK(inserted);
}
vda_loop_proxy_->PostTask(FROM_HERE, base::Bind(
- &VideoDecodeAccelerator::AssignPictureBuffers, vda_, picture_buffers));
+ &VideoDecodeAccelerator::AssignPictureBuffers, weak_vda_,
+ picture_buffers));
}
void GpuVideoDecoder::DismissPictureBuffer(int32 id) {
@@ -409,10 +419,11 @@ void GpuVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id) {
&GpuVideoDecoder::ReusePictureBuffer, this, picture_buffer_id));
return;
}
- if (!vda_)
+ if (!vda_.get())
return;
vda_loop_proxy_->PostTask(FROM_HERE, base::Bind(
- &VideoDecodeAccelerator::ReusePictureBuffer, vda_, picture_buffer_id));
+ &VideoDecodeAccelerator::ReusePictureBuffer, weak_vda_,
+ picture_buffer_id));
}
GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) {
@@ -467,7 +478,7 @@ void GpuVideoDecoder::NotifyEndOfBitstreamBuffer(int32 id) {
}
GpuVideoDecoder::~GpuVideoDecoder() {
- DCHECK(!vda_); // Stop should have been already called.
+ DCHECK(!vda_.get()); // Stop should have been already called.
DCHECK(pending_read_cb_.is_null());
for (size_t i = 0; i < available_shm_segments_.size(); ++i) {
available_shm_segments_[i]->shm->Close();
@@ -510,7 +521,7 @@ void GpuVideoDecoder::NotifyResetDone() {
return;
}
- if (!vda_)
+ if (!vda_.get())
return;
DCHECK(ready_video_frames_.empty());
@@ -532,9 +543,9 @@ void GpuVideoDecoder::NotifyError(media::VideoDecodeAccelerator::Error error) {
&GpuVideoDecoder::NotifyError, this, error));
return;
}
- if (!vda_)
+ if (!vda_.get())
return;
- vda_ = NULL;
+ vda_loop_proxy_->DeleteSoon(FROM_HERE, vda_.release());
DLOG(ERROR) << "VDA Error: " << error;
error_occured_ = true;

Powered by Google App Engine
This is Rietveld 408576698