Skip to content

Commit

Permalink
Convert VideoEncodeAccelerator to new Mojo types
Browse files Browse the repository at this point in the history
This CL converts VideoEncodeAccelerator to new Mojo types
using PendingReceiver, PendingRemote, Remote and
SelfOwnedReceiver.

Bug: 955171
Change-Id: I2b8acd2c1e9e2f033679d5574a183a3067e0ae8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1886281
Reviewed-by: Gyuyoung Kim <gyuyoung@igalia.com>
Reviewed-by: Xiaohan Wang <xhwang@chromium.org>
Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: Yuri Wiitala <miu@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#711956}
  • Loading branch information
jkim-julie authored and Commit Bot committed Nov 2, 2019
1 parent d5fbc93 commit e1b0d1a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
5 changes: 3 additions & 2 deletions components/mirroring/service/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,9 @@ void Session::CreateVideoEncodeAccelerator(
gpu_->CreateVideoEncodeAcceleratorProvider(
mojo::MakeRequest(&vea_provider_));
}
media::mojom::VideoEncodeAcceleratorPtr vea;
vea_provider_->CreateVideoEncodeAccelerator(mojo::MakeRequest(&vea));
mojo::PendingRemote<media::mojom::VideoEncodeAccelerator> vea;
vea_provider_->CreateVideoEncodeAccelerator(
vea.InitWithNewPipeAndPassReceiver());
// std::make_unique doesn't work to create a unique pointer of the subclass.
mojo_vea.reset(new media::MojoVideoEncodeAccelerator(std::move(vea),
supported_profiles_));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ GpuVideoAcceleratorFactoriesImpl::CreateVideoEncodeAccelerator() {
if (CheckContextLost())
return nullptr;

media::mojom::VideoEncodeAcceleratorPtr vea;
vea_provider_->CreateVideoEncodeAccelerator(mojo::MakeRequest(&vea));
mojo::PendingRemote<media::mojom::VideoEncodeAccelerator> vea;
vea_provider_->CreateVideoEncodeAccelerator(
vea.InitWithNewPipeAndPassReceiver());

if (!vea)
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion media/mojo/clients/mojo_video_encode_accelerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void VideoEncodeAcceleratorClient::NotifyError(
} // anonymous namespace

MojoVideoEncodeAccelerator::MojoVideoEncodeAccelerator(
mojom::VideoEncodeAcceleratorPtr vea,
mojo::PendingRemote<mojom::VideoEncodeAccelerator> vea,
const gpu::VideoEncodeAcceleratorSupportedProfiles& supported_profiles)
: vea_(std::move(vea)), supported_profiles_(supported_profiles) {
DVLOG(1) << __func__;
Expand Down
6 changes: 4 additions & 2 deletions media/mojo/clients/mojo_video_encode_accelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "gpu/config/gpu_info.h"
#include "media/mojo/mojom/video_encode_accelerator.mojom.h"
#include "media/video/video_encode_accelerator.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"

namespace media {
class VideoFrame;
Expand All @@ -29,7 +31,7 @@ namespace media {
class MojoVideoEncodeAccelerator : public VideoEncodeAccelerator {
public:
MojoVideoEncodeAccelerator(
mojom::VideoEncodeAcceleratorPtr vea,
mojo::PendingRemote<mojom::VideoEncodeAccelerator> vea,
const gpu::VideoEncodeAcceleratorSupportedProfiles& supported_profiles);

// VideoEncodeAccelerator implementation.
Expand All @@ -47,7 +49,7 @@ class MojoVideoEncodeAccelerator : public VideoEncodeAccelerator {
// Only Destroy() should be deleting |this|.
~MojoVideoEncodeAccelerator() override;

mojom::VideoEncodeAcceleratorPtr vea_;
mojo::Remote<mojom::VideoEncodeAccelerator> vea_;

// Constructed during Initialize().
std::unique_ptr<mojom::VideoEncodeAcceleratorClient> vea_client_;
Expand Down
21 changes: 11 additions & 10 deletions media/mojo/clients/mojo_video_encode_accelerator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#include "media/mojo/clients/mojo_video_encode_accelerator.h"
#include "media/mojo/mojom/video_encode_accelerator.mojom.h"
#include "media/video/video_encode_accelerator.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down Expand Up @@ -123,25 +124,25 @@ class MojoVideoEncodeAcceleratorTest : public ::testing::Test {
MojoVideoEncodeAcceleratorTest() = default;

void SetUp() override {
mojom::VideoEncodeAcceleratorPtr mojo_vea;
mojo_vea_binding_ = mojo::MakeStrongBinding(
mojo::PendingRemote<mojom::VideoEncodeAccelerator> mojo_vea;
mojo_vea_receiver_ = mojo::MakeSelfOwnedReceiver(
std::make_unique<MockMojoVideoEncodeAccelerator>(),
mojo::MakeRequest(&mojo_vea));
mojo_vea.InitWithNewPipeAndPassReceiver());

mojo_vea_.reset(new MojoVideoEncodeAccelerator(
std::move(mojo_vea), gpu::VideoEncodeAcceleratorSupportedProfiles()));
}

void TearDown() override {
// The destruction of a mojo::StrongBinding closes the bound message pipe
// but does not destroy the implementation object(s): this needs to happen
// manually by Close()ing it.
mojo_vea_binding_->Close();
// The destruction of a mojo::SelfOwnedReceiver closes the bound message
// pipe but does not destroy the implementation object(s): this needs to
// happen manually by Close()ing it.
mojo_vea_receiver_->Close();
}

MockMojoVideoEncodeAccelerator* mock_mojo_vea() {
return static_cast<media::MockMojoVideoEncodeAccelerator*>(
mojo_vea_binding_->impl());
mojo_vea_receiver_->impl());
}
VideoEncodeAccelerator* mojo_vea() { return mojo_vea_.get(); }

Expand Down Expand Up @@ -175,7 +176,7 @@ class MojoVideoEncodeAcceleratorTest : public ::testing::Test {
base::test::SingleThreadTaskEnvironment task_environment_;

// This member holds on to the mock implementation of the "service" side.
mojo::StrongBindingPtr<mojom::VideoEncodeAccelerator> mojo_vea_binding_;
mojo::SelfOwnedReceiverRef<mojom::VideoEncodeAccelerator> mojo_vea_receiver_;

// The class under test, as a generic media::VideoEncodeAccelerator.
std::unique_ptr<VideoEncodeAccelerator> mojo_vea_;
Expand Down
25 changes: 13 additions & 12 deletions media/mojo/test/mojo_video_encode_accelerator_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#include "media/mojo/services/mojo_video_encode_accelerator_service.h"
#include "media/video/fake_video_encode_accelerator.h"
#include "media/video/video_encode_accelerator.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down Expand Up @@ -63,30 +64,30 @@ class MojoVideoEncodeAcceleratorIntegrationTest : public ::testing::Test {
MojoVideoEncodeAcceleratorIntegrationTest() = default;

void SetUp() override {
mojom::VideoEncodeAcceleratorPtr mojo_vea;
mojo_vea_binding_ = mojo::MakeStrongBinding(
mojo::PendingRemote<mojom::VideoEncodeAccelerator> mojo_vea;
mojo_vea_receiver_ = mojo::MakeSelfOwnedReceiver(
std::make_unique<MojoVideoEncodeAcceleratorService>(
base::Bind(&CreateAndInitializeFakeVEA), gpu::GpuPreferences()),
mojo::MakeRequest(&mojo_vea));
mojo_vea.InitWithNewPipeAndPassReceiver());

mojo_vea_.reset(new MojoVideoEncodeAccelerator(
std::move(mojo_vea), gpu::VideoEncodeAcceleratorSupportedProfiles()));
}

void TearDown() override {
// The destruction of a mojo::StrongBinding closes the bound message pipe
// but does not destroy the implementation object(s): this needs to happen
// manually by Close()ing it.
if (mojo_vea_binding_)
mojo_vea_binding_->Close();
// The destruction of a mojo::SelfOwnedReceiver closes the bound message
// pipe but does not destroy the implementation object(s): this needs to
// happen manually by Close()ing it.
if (mojo_vea_receiver_)
mojo_vea_receiver_->Close();
}

VideoEncodeAccelerator* mojo_vea() { return mojo_vea_.get(); }

FakeVideoEncodeAccelerator* fake_vea() const {
const auto* mojo_vea_service =
static_cast<MojoVideoEncodeAcceleratorService*>(
mojo_vea_binding_->impl());
mojo_vea_receiver_->impl());
return static_cast<FakeVideoEncodeAccelerator*>(
mojo_vea_service->encoder_.get());
}
Expand All @@ -111,7 +112,7 @@ class MojoVideoEncodeAcceleratorIntegrationTest : public ::testing::Test {
base::test::SingleThreadTaskEnvironment task_environment_;

// This member holds on to the implementation of the "service" side.
mojo::StrongBindingPtr<mojom::VideoEncodeAccelerator> mojo_vea_binding_;
mojo::SelfOwnedReceiverRef<mojom::VideoEncodeAccelerator> mojo_vea_receiver_;

// The class under test, as a generic media::VideoEncodeAccelerator.
std::unique_ptr<VideoEncodeAccelerator> mojo_vea_;
Expand Down Expand Up @@ -356,7 +357,7 @@ TEST_F(MojoVideoEncodeAcceleratorIntegrationTest,
Initialize(mock_vea_client.get());

{
TearDown(); // Alias for |mojo_vea_binding_| Close().
TearDown(); // Alias for |mojo_vea_receiver_| Close().
base::RunLoop().RunUntilIdle();
}
{
Expand Down

0 comments on commit e1b0d1a

Please sign in to comment.