Commit 5c1dffb2 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Switch RTCVideoDecoderAdapter away from base::Bind

... and use its WTF counterparts.

BUG=78725
R=haraken@chromium.org

Change-Id: Ib706c5c63a41363ca85effa42f0970ed60d660e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1778664
Auto-Submit: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#692388}
parent 327a2fd6
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#include <functional> #include <functional>
#include <utility> #include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -29,8 +27,10 @@ ...@@ -29,8 +27,10 @@
#include "media/video/gpu_video_accelerator_factories.h" #include "media/video/gpu_video_accelerator_factories.h"
#include "media/video/video_decode_accelerator.h" #include "media/video/video_decode_accelerator.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/webrtc/webrtc_video_frame_adapter.h" #include "third_party/blink/renderer/platform/webrtc/webrtc_video_frame_adapter.h"
#include "third_party/blink/renderer/platform/webrtc/webrtc_video_utils.h" #include "third_party/blink/renderer/platform/webrtc/webrtc_video_utils.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/webrtc/api/video/video_frame.h" #include "third_party/webrtc/api/video/video_frame.h"
#include "third_party/webrtc/media/base/vp9_profile.h" #include "third_party/webrtc/media/base/vp9_profile.h"
#include "third_party/webrtc/modules/video_coding/codecs/h264/include/h264.h" #include "third_party/webrtc/modules/video_coding/codecs/h264/include/h264.h"
...@@ -39,6 +39,16 @@ ...@@ -39,6 +39,16 @@
#include "third_party/webrtc/rtc_base/ref_counted_object.h" #include "third_party/webrtc/rtc_base/ref_counted_object.h"
#include "ui/gfx/color_space.h" #include "ui/gfx/color_space.h"
namespace WTF {
template <>
struct CrossThreadCopier<media::VideoDecoderConfig>
: public CrossThreadCopierPassThrough<media::VideoDecoderConfig> {
STATIC_ONLY(CrossThreadCopier);
};
} // namespace WTF
namespace blink { namespace blink {
namespace { namespace {
...@@ -189,12 +199,14 @@ bool RTCVideoDecoderAdapter::InitializeSync( ...@@ -189,12 +199,14 @@ bool RTCVideoDecoderAdapter::InitializeSync(
bool result = false; bool result = false;
base::WaitableEvent waiter(base::WaitableEvent::ResetPolicy::MANUAL, base::WaitableEvent waiter(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED); base::WaitableEvent::InitialState::NOT_SIGNALED);
media::VideoDecoder::InitCB init_cb = auto init_cb =
base::BindOnce(&FinishWait, &waiter, &result); CrossThreadBindOnce(&FinishWait, CrossThreadUnretained(&waiter),
if (media_task_runner_->PostTask( CrossThreadUnretained(&result));
FROM_HERE, if (PostCrossThreadTask(
base::BindOnce(&RTCVideoDecoderAdapter::InitializeOnMediaThread, *media_task_runner_.get(), FROM_HERE,
base::Unretained(this), config, std::move(init_cb)))) { CrossThreadBindOnce(&RTCVideoDecoderAdapter::InitializeOnMediaThread,
CrossThreadUnretained(this), config,
std::move(init_cb)))) {
waiter.Wait(); waiter.Wait();
} }
return result; return result;
...@@ -308,9 +320,10 @@ int32_t RTCVideoDecoderAdapter::Decode(const webrtc::EncodedImage& input_image, ...@@ -308,9 +320,10 @@ int32_t RTCVideoDecoderAdapter::Decode(const webrtc::EncodedImage& input_image,
} }
pending_buffers_.push_back(std::move(buffer)); pending_buffers_.push_back(std::move(buffer));
} }
media_task_runner_->PostTask( PostCrossThreadTask(
FROM_HERE, *media_task_runner_.get(), FROM_HERE,
base::BindOnce(&RTCVideoDecoderAdapter::DecodeOnMediaThread, weak_this_)); CrossThreadBindOnce(&RTCVideoDecoderAdapter::DecodeOnMediaThread,
weak_this_));
return WEBRTC_VIDEO_CODEC_OK; return WEBRTC_VIDEO_CODEC_OK;
} }
...@@ -343,7 +356,7 @@ const char* RTCVideoDecoderAdapter::ImplementationName() const { ...@@ -343,7 +356,7 @@ const char* RTCVideoDecoderAdapter::ImplementationName() const {
void RTCVideoDecoderAdapter::InitializeOnMediaThread( void RTCVideoDecoderAdapter::InitializeOnMediaThread(
const media::VideoDecoderConfig& config, const media::VideoDecoderConfig& config,
media::VideoDecoder::InitCB init_cb) { InitCB init_cb) {
DVLOG(3) << __func__; DVLOG(3) << __func__;
DCHECK(media_task_runner_->BelongsToCurrentThread()); DCHECK(media_task_runner_->BelongsToCurrentThread());
...@@ -355,11 +368,11 @@ void RTCVideoDecoderAdapter::InitializeOnMediaThread( ...@@ -355,11 +368,11 @@ void RTCVideoDecoderAdapter::InitializeOnMediaThread(
video_decoder_ = gpu_factories_->CreateVideoDecoder( video_decoder_ = gpu_factories_->CreateVideoDecoder(
media_log_.get(), kImplementation, media_log_.get(), kImplementation,
base::BindRepeating(&OnRequestOverlayInfo)); WTF::BindRepeating(&OnRequestOverlayInfo));
if (!video_decoder_) { if (!video_decoder_) {
media_task_runner_->PostTask(FROM_HERE, PostCrossThreadTask(*media_task_runner_.get(), FROM_HERE,
base::BindOnce(std::move(init_cb), false)); CrossThreadBindOnce(std::move(init_cb), false));
return; return;
} }
} }
...@@ -370,10 +383,10 @@ void RTCVideoDecoderAdapter::InitializeOnMediaThread( ...@@ -370,10 +383,10 @@ void RTCVideoDecoderAdapter::InitializeOnMediaThread(
// Encryption is not supported. // Encryption is not supported.
media::CdmContext* cdm_context = nullptr; media::CdmContext* cdm_context = nullptr;
media::VideoDecoder::OutputCB output_cb = media::VideoDecoder::OutputCB output_cb = ConvertToBaseCallback(
base::BindRepeating(&RTCVideoDecoderAdapter::OnOutput, weak_this_); CrossThreadBindRepeating(&RTCVideoDecoderAdapter::OnOutput, weak_this_));
video_decoder_->Initialize(config, low_delay, cdm_context,
video_decoder_->Initialize(config, low_delay, cdm_context, std::move(init_cb), ConvertToBaseOnceCallback(std::move(init_cb)),
output_cb, base::DoNothing()); output_cb, base::DoNothing());
} }
...@@ -403,7 +416,7 @@ void RTCVideoDecoderAdapter::DecodeOnMediaThread() { ...@@ -403,7 +416,7 @@ void RTCVideoDecoderAdapter::DecodeOnMediaThread() {
outstanding_decode_requests_++; outstanding_decode_requests_++;
video_decoder_->Decode( video_decoder_->Decode(
std::move(buffer), std::move(buffer),
base::BindRepeating(&RTCVideoDecoderAdapter::OnDecodeDone, weak_this_)); WTF::BindRepeating(&RTCVideoDecoderAdapter::OnDecodeDone, weak_this_));
} }
} }
...@@ -482,17 +495,20 @@ bool RTCVideoDecoderAdapter::ReinitializeSync( ...@@ -482,17 +495,20 @@ bool RTCVideoDecoderAdapter::ReinitializeSync(
bool result = false; bool result = false;
base::WaitableEvent waiter(base::WaitableEvent::ResetPolicy::MANUAL, base::WaitableEvent waiter(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED); base::WaitableEvent::InitialState::NOT_SIGNALED);
media::VideoDecoder::InitCB init_cb = auto init_cb =
base::BindRepeating(&FinishWait, &waiter, &result); CrossThreadBindOnce(&FinishWait, CrossThreadUnretained(&waiter),
CrossThreadUnretained(&result));
FlushDoneCB flush_success_cb = FlushDoneCB flush_success_cb =
base::BindOnce(&RTCVideoDecoderAdapter::InitializeOnMediaThread, CrossThreadBindOnce(&RTCVideoDecoderAdapter::InitializeOnMediaThread,
weak_this_, config, std::move(init_cb)); weak_this_, config, std::move(init_cb));
FlushDoneCB flush_fail_cb = FlushDoneCB flush_fail_cb =
base::BindOnce(&FinishWait, &waiter, &result, false); CrossThreadBindOnce(&FinishWait, CrossThreadUnretained(&waiter),
if (media_task_runner_->PostTask( CrossThreadUnretained(&result), false);
FROM_HERE, base::BindOnce(&RTCVideoDecoderAdapter::FlushOnMediaThread, if (PostCrossThreadTask(
weak_this_, std::move(flush_success_cb), *media_task_runner_.get(), FROM_HERE,
std::move(flush_fail_cb)))) { CrossThreadBindOnce(&RTCVideoDecoderAdapter::FlushOnMediaThread,
weak_this_, std::move(flush_success_cb),
std::move(flush_fail_cb)))) {
waiter.Wait(); waiter.Wait();
} }
return result; return result;
...@@ -511,7 +527,7 @@ void RTCVideoDecoderAdapter::FlushOnMediaThread(FlushDoneCB flush_success_cb, ...@@ -511,7 +527,7 @@ void RTCVideoDecoderAdapter::FlushOnMediaThread(FlushDoneCB flush_success_cb,
// Send EOS frame for flush. // Send EOS frame for flush.
video_decoder_->Decode( video_decoder_->Decode(
media::DecoderBuffer::CreateEOSBuffer(), media::DecoderBuffer::CreateEOSBuffer(),
base::BindRepeating( WTF::BindRepeating(
[](FlushDoneCB flush_success, FlushDoneCB flush_fail, [](FlushDoneCB flush_success, FlushDoneCB flush_fail,
media::DecodeStatus status) { media::DecodeStatus status) {
if (status == media::DecodeStatus::OK) if (status == media::DecodeStatus::OK)
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "media/base/video_decoder_config.h" #include "media/base/video_decoder_config.h"
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/deque.h" #include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/webrtc/api/video_codecs/sdp_video_format.h" #include "third_party/webrtc/api/video_codecs/sdp_video_format.h"
#include "third_party/webrtc/modules/video_coding/include/video_codec_interface.h" #include "third_party/webrtc/modules/video_coding/include/video_codec_interface.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -80,7 +81,8 @@ class PLATFORM_EXPORT RTCVideoDecoderAdapter : public webrtc::VideoDecoder { ...@@ -80,7 +81,8 @@ class PLATFORM_EXPORT RTCVideoDecoderAdapter : public webrtc::VideoDecoder {
using CreateVideoDecoderCB = using CreateVideoDecoderCB =
base::RepeatingCallback<std::unique_ptr<media::VideoDecoder>( base::RepeatingCallback<std::unique_ptr<media::VideoDecoder>(
media::MediaLog*)>; media::MediaLog*)>;
using FlushDoneCB = base::OnceCallback<void()>; using InitCB = CrossThreadOnceFunction<void(bool)>;
using FlushDoneCB = CrossThreadOnceFunction<void()>;
// Called on the worker thread. // Called on the worker thread.
RTCVideoDecoderAdapter(media::GpuVideoAcceleratorFactories* gpu_factories, RTCVideoDecoderAdapter(media::GpuVideoAcceleratorFactories* gpu_factories,
...@@ -89,7 +91,7 @@ class PLATFORM_EXPORT RTCVideoDecoderAdapter : public webrtc::VideoDecoder { ...@@ -89,7 +91,7 @@ class PLATFORM_EXPORT RTCVideoDecoderAdapter : public webrtc::VideoDecoder {
bool InitializeSync(const media::VideoDecoderConfig& config); bool InitializeSync(const media::VideoDecoderConfig& config);
void InitializeOnMediaThread(const media::VideoDecoderConfig& config, void InitializeOnMediaThread(const media::VideoDecoderConfig& config,
media::VideoDecoder::InitCB init_cb); InitCB init_cb);
void DecodeOnMediaThread(); void DecodeOnMediaThread();
void OnDecodeDone(media::DecodeStatus status); void OnDecodeDone(media::DecodeStatus status);
void OnOutput(scoped_refptr<media::VideoFrame> frame); void OnOutput(scoped_refptr<media::VideoFrame> frame);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment