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

Unified Diff: content/renderer/media/rtc_video_decoder.cc

Issue 27420004: Remove threading from RendererGpuVideoAcceleratorFactories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dthread
Patch Set: 2d3efbfa Rebase. Created 7 years, 2 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/renderer/media/rtc_video_decoder.cc
diff --git a/content/renderer/media/rtc_video_decoder.cc b/content/renderer/media/rtc_video_decoder.cc
index 5c470fdb4b18cdbadaffef90a4c6ec01b02bb1ee..67bb8d2796674c2bfe0685976f37d6ec5b795e95 100644
--- a/content/renderer/media/rtc_video_decoder.cc
+++ b/content/renderer/media/rtc_video_decoder.cc
@@ -11,11 +11,13 @@
#include "base/metrics/histogram.h"
#include "base/safe_numerics.h"
#include "base/stl_util.h"
+#include "base/synchronization/waitable_event.h"
#include "base/task_runner_util.h"
#include "content/child/child_thread.h"
#include "content/renderer/media/native_handle_impl.h"
#include "media/base/bind_to_loop.h"
#include "media/filters/gpu_video_accelerator_factories.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/webrtc/common_video/interface/texture_video_frame.h"
#include "third_party/webrtc/system_wrappers/interface/ref_count.h"
@@ -83,29 +85,12 @@ RTCVideoDecoder::RTCVideoDecoder(
decode_complete_callback_(NULL),
num_shm_buffers_(0),
next_bitstream_buffer_id_(0),
- reset_bitstream_buffer_id_(ID_INVALID) {
- DCHECK(!vda_loop_proxy_->BelongsToCurrentThread());
- base::WaitableEvent message_loop_async_waiter(false, false);
- // Waiting here is safe. The media thread is stopped in the child thread and
- // the child thread is blocked when VideoDecoderFactory::CreateVideoDecoder
- // runs.
- vda_loop_proxy_->PostTask(FROM_HERE,
- base::Bind(&RTCVideoDecoder::Initialize,
- base::Unretained(this),
- &message_loop_async_waiter));
- message_loop_async_waiter.Wait();
-}
+ reset_bitstream_buffer_id_(ID_INVALID) {}
RTCVideoDecoder::~RTCVideoDecoder() {
DVLOG(2) << "~RTCVideoDecoder";
- // Destroy VDA and remove |this| from the observer if this is vda thread.
- if (vda_loop_proxy_->BelongsToCurrentThread()) {
- base::MessageLoop::current()->RemoveDestructionObserver(this);
- DestroyVDA();
- } else {
- // VDA should have been destroyed in WillDestroyCurrentMessageLoop.
- DCHECK(!vda_);
- }
+ DCHECK(vda_loop_proxy_->BelongsToCurrentThread());
+ DestroyVDA();
// Delete all shared memories.
STLDeleteElements(&available_shm_segments_);
@@ -123,6 +108,7 @@ RTCVideoDecoder::~RTCVideoDecoder() {
}
}
+// static
scoped_ptr<RTCVideoDecoder> RTCVideoDecoder::Create(
webrtc::VideoCodecType type,
const scoped_refptr<media::GpuVideoAcceleratorFactories>& factories) {
@@ -138,9 +124,14 @@ scoped_ptr<RTCVideoDecoder> RTCVideoDecoder::Create(
return decoder.Pass();
}
+ base::WaitableEvent waiter(true, false);
decoder.reset(new RTCVideoDecoder(factories));
- decoder->vda_ =
- factories->CreateVideoDecodeAccelerator(profile, decoder.get()).Pass();
+ decoder->vda_loop_proxy_->PostTask(FROM_HERE,
+ base::Bind(&RTCVideoDecoder::CreateVDA,
+ base::Unretained(decoder.get()),
+ profile,
+ &waiter));
+ waiter.Wait();
// vda can be NULL if VP8 is not supported.
if (decoder->vda_ != NULL) {
decoder->state_ = INITIALIZED;
@@ -406,10 +397,12 @@ scoped_refptr<media::VideoFrame> RTCVideoDecoder::CreateVideoFrame(
visible_rect,
natural_size,
timestamp_ms,
- base::Bind(&media::GpuVideoAcceleratorFactories::ReadPixels,
- factories_,
- pb.texture_id(),
- natural_size),
+ media::BindToLoopSync(
+ factories_->GetMessageLoop(), base::Bind(
+ &media::GpuVideoAcceleratorFactories::ReadPixels,
+ factories_,
+ pb.texture_id(),
+ natural_size)),
base::Closure());
}
@@ -470,21 +463,6 @@ void RTCVideoDecoder::NotifyError(media::VideoDecodeAccelerator::Error error) {
state_ = DECODE_ERROR;
}
-void RTCVideoDecoder::WillDestroyCurrentMessageLoop() {
- DVLOG(2) << "WillDestroyCurrentMessageLoop";
- DCHECK(vda_loop_proxy_->BelongsToCurrentThread());
- factories_->Abort();
- weak_factory_.InvalidateWeakPtrs();
- DestroyVDA();
-}
-
-void RTCVideoDecoder::Initialize(base::WaitableEvent* waiter) {
- DVLOG(2) << "Initialize";
- DCHECK(vda_loop_proxy_->BelongsToCurrentThread());
- base::MessageLoop::current()->AddDestructionObserver(this);
- waiter->Signal();
-}
-
void RTCVideoDecoder::RequestBufferDecode() {
DCHECK(vda_loop_proxy_->BelongsToCurrentThread());
if (!vda_)
@@ -644,6 +622,13 @@ void RTCVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id,
vda_->ReusePictureBuffer(picture_buffer_id);
}
+void RTCVideoDecoder::CreateVDA(media::VideoCodecProfile profile,
+ base::WaitableEvent* waiter) {
+ DCHECK(vda_loop_proxy_->BelongsToCurrentThread());
+ vda_ = factories_->CreateVideoDecodeAccelerator(profile, this);
+ waiter->Signal();
+}
+
void RTCVideoDecoder::DestroyTextures() {
DCHECK(vda_loop_proxy_->BelongsToCurrentThread());
std::map<int32, media::PictureBuffer>::iterator it;

Powered by Google App Engine
This is Rietveld 408576698