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

Unified Diff: content/common/gpu/media/omx_video_decode_accelerator.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: content/common/gpu/media/omx_video_decode_accelerator.cc
diff --git a/content/common/gpu/media/omx_video_decode_accelerator.cc b/content/common/gpu/media/omx_video_decode_accelerator.cc
index 7bcd1bb57fe98a2760d51b0d25730752d8bf32e7..9818626544d185c88a5b0ead702a325181e62c7e 100644
--- a/content/common/gpu/media/omx_video_decode_accelerator.cc
+++ b/content/common/gpu/media/omx_video_decode_accelerator.cc
@@ -190,7 +190,6 @@ bool OmxVideoDecodeAccelerator::CreateComponent() {
PLATFORM_FAILURE, false);
// Get the handle to the component.
- AddRef(); // To reflect passing |this| to OMX_GetHandle below.
result = omx_gethandle(
&component_handle_, reinterpret_cast<OMX_STRING>(component.get()),
this, &omx_accelerator_callbacks);
@@ -437,7 +436,8 @@ void OmxVideoDecodeAccelerator::Reset() {
BeginTransitionToState(OMX_StatePause);
}
-void OmxVideoDecodeAccelerator::Destroy() {
+void OmxVideoDecodeAccelerator::Destroy(
+ scoped_ptr<VideoDecodeAccelerator> self) {
DCHECK_EQ(message_loop_, MessageLoop::current());
if (current_state_change_ == ERRORING ||
current_state_change_ == DESTROYING) {
@@ -462,7 +462,7 @@ void OmxVideoDecodeAccelerator::Destroy() {
current_state_change_ = DESTROYING;
client_ = NULL;
BeginTransitionToState(OMX_StateIdle);
- BusyLoopInDestroying();
+ BusyLoopInDestroying(self.Pass());
}
void OmxVideoDecodeAccelerator::BeginTransitionToState(
@@ -562,14 +562,16 @@ void OmxVideoDecodeAccelerator::OnReachedExecutingInResetting() {
// outlives the shutdown dance, even during process shutdown. We do this by
// repeatedly enqueuing a no-op task until shutdown is complete, since
// MessageLoop's shutdown drains pending tasks.
-void OmxVideoDecodeAccelerator::BusyLoopInDestroying() {
+void OmxVideoDecodeAccelerator::BusyLoopInDestroying(
+ scoped_ptr<VideoDecodeAccelerator> self) {
if (!component_handle_) return;
// Can't use PostDelayedTask here because MessageLoop doesn't drain delayed
// tasks. Instead we sleep for 5ms. Really.
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5));
message_loop_->PostTask(
FROM_HERE, base::Bind(
- &OmxVideoDecodeAccelerator::BusyLoopInDestroying, this));
+ &OmxVideoDecodeAccelerator::BusyLoopInDestroying,
+ base::Unretained(this), base::Passed(&self)));
}
void OmxVideoDecodeAccelerator::OnReachedIdleInDestroying() {
@@ -590,8 +592,6 @@ void OmxVideoDecodeAccelerator::OnReachedIdleInDestroying() {
FreeInputBuffers();
if (!output_buffers_at_component_)
FreeOutputBuffers();
-
- BusyLoopInDestroying();
}
void OmxVideoDecodeAccelerator::OnReachedLoadedInDestroying() {
@@ -610,12 +610,10 @@ void OmxVideoDecodeAccelerator::ShutdownComponent() {
OMX_ERRORTYPE result = omx_free_handle(component_handle_);
if (result != OMX_ErrorNone)
DLOG(ERROR) << "OMX_FreeHandle() error. Error code: " << result;
- component_handle_ = NULL;
client_state_ = OMX_StateMax;
- // This Release() call must happen *after* any access to |*this| because it
- // might result in |this| being deleted.
- Release(); // Since OMX no longer has |this| to call back to.
omx_deinit();
+ // Allow BusyLoopInDestroying to exit and delete |this|.
+ component_handle_ = NULL;
}
void OmxVideoDecodeAccelerator::StopOnError(
@@ -1000,8 +998,8 @@ OMX_ERRORTYPE OmxVideoDecodeAccelerator::EventHandler(OMX_HANDLETYPE component,
static_cast<OmxVideoDecodeAccelerator*>(priv_data);
DCHECK_EQ(component, decoder->component_handle_);
decoder->message_loop_->PostTask(FROM_HERE, base::Bind(
- &OmxVideoDecodeAccelerator::EventHandlerCompleteTask, decoder,
- event, data1, data2));
+ &OmxVideoDecodeAccelerator::EventHandlerCompleteTask,
+ base::AsWeakPtr(decoder), event, data1, data2));
return OMX_ErrorNone;
}
@@ -1017,7 +1015,8 @@ OMX_ERRORTYPE OmxVideoDecodeAccelerator::EmptyBufferCallback(
static_cast<OmxVideoDecodeAccelerator*>(priv_data);
DCHECK_EQ(component, decoder->component_handle_);
decoder->message_loop_->PostTask(FROM_HERE, base::Bind(
- &OmxVideoDecodeAccelerator::EmptyBufferDoneTask, decoder, buffer));
+ &OmxVideoDecodeAccelerator::EmptyBufferDoneTask, base::AsWeakPtr(decoder),
+ buffer));
return OMX_ErrorNone;
}
@@ -1037,7 +1036,8 @@ OMX_ERRORTYPE OmxVideoDecodeAccelerator::FillBufferCallback(
static_cast<OmxVideoDecodeAccelerator*>(priv_data);
DCHECK_EQ(component, decoder->component_handle_);
decoder->message_loop_->PostTask(FROM_HERE, base::Bind(
- &OmxVideoDecodeAccelerator::FillBufferDoneTask, decoder, buffer));
+ &OmxVideoDecodeAccelerator::FillBufferDoneTask, base::AsWeakPtr(decoder),
+ buffer));
return OMX_ErrorNone;
}

Powered by Google App Engine
This is Rietveld 408576698