diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-09-01 11:08:40 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-10-01 12:16:21 +0000 |
commit | 03c549e0392f92c02536d3f86d5e1d8dfa3435ac (patch) | |
tree | fe49d170a929b34ba82cd10db1a0bd8e3760fa4b /chromium/media/mojo/clients | |
parent | 5d013f5804a0d91fcf6c626b2d6fb6eca5c845b0 (diff) | |
download | qtwebengine-chromium-03c549e0392f92c02536d3f86d5e1d8dfa3435ac.tar.gz |
BASELINE: Update Chromium to 91.0.4472.160
Change-Id: I0def1f08a2412aeed79a9ab95dd50eb5c3f65f31
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/media/mojo/clients')
14 files changed, 121 insertions, 154 deletions
diff --git a/chromium/media/mojo/clients/mojo_audio_decoder.cc b/chromium/media/mojo/clients/mojo_audio_decoder.cc index 2bf1b1a59b9..76259add30c 100644 --- a/chromium/media/mojo/clients/mojo_audio_decoder.cc +++ b/chromium/media/mojo/clients/mojo_audio_decoder.cc @@ -51,10 +51,6 @@ AudioDecoderType MojoAudioDecoder::GetDecoderType() const { return decoder_type_; } -std::string MojoAudioDecoder::GetDisplayName() const { - return "MojoAudioDecoder"; -} - void MojoAudioDecoder::FailInit(InitCB init_cb, Status err) { task_runner_->PostTask(FROM_HERE, base::BindOnce(std::move(init_cb), std::move(err))); diff --git a/chromium/media/mojo/clients/mojo_audio_decoder.h b/chromium/media/mojo/clients/mojo_audio_decoder.h index fbb85ab5f72..04a40615daa 100644 --- a/chromium/media/mojo/clients/mojo_audio_decoder.h +++ b/chromium/media/mojo/clients/mojo_audio_decoder.h @@ -36,7 +36,6 @@ class MojoAudioDecoder final : public AudioDecoder, // Decoder implementation bool IsPlatformDecoder() const final; bool SupportsDecryption() const final; - std::string GetDisplayName() const override; AudioDecoderType GetDecoderType() const override; // AudioDecoder implementation. diff --git a/chromium/media/mojo/clients/mojo_audio_decoder_unittest.cc b/chromium/media/mojo/clients/mojo_audio_decoder_unittest.cc index daba06f1470..8f4ad6ca715 100644 --- a/chromium/media/mojo/clients/mojo_audio_decoder_unittest.cc +++ b/chromium/media/mojo/clients/mojo_audio_decoder_unittest.cc @@ -65,9 +65,9 @@ class MojoAudioDecoderTest : public ::testing::Test { base::BindOnce(&MojoAudioDecoderTest::ConnectToService, base::Unretained(this), remote_audio_decoder.InitWithNewPipeAndPassReceiver())); - mojo_audio_decoder_.reset( - new MojoAudioDecoder(task_environment_.GetMainThreadTaskRunner(), - std::move(remote_audio_decoder))); + mojo_audio_decoder_ = std::make_unique<MojoAudioDecoder>( + task_environment_.GetMainThreadTaskRunner(), + std::move(remote_audio_decoder)); } ~MojoAudioDecoderTest() override { @@ -91,13 +91,13 @@ class MojoAudioDecoderTest : public ::testing::Test { void RunLoop() { DVLOG(1) << __func__; - run_loop_.reset(new base::RunLoop()); + run_loop_ = std::make_unique<base::RunLoop>(); run_loop_->Run(); } void RunLoopUntilIdle() { DVLOG(1) << __func__; - run_loop_.reset(new base::RunLoop()); + run_loop_ = std::make_unique<base::RunLoop>(); run_loop_->RunUntilIdle(); } diff --git a/chromium/media/mojo/clients/mojo_cdm.cc b/chromium/media/mojo/clients/mojo_cdm.cc index 403c19f040f..f0098346345 100644 --- a/chromium/media/mojo/clients/mojo_cdm.cc +++ b/chromium/media/mojo/clients/mojo_cdm.cc @@ -36,21 +36,24 @@ void RecordConnectionError(bool connection_error_happened) { } // namespace MojoCdm::MojoCdm(mojo::Remote<mojom::ContentDecryptionModule> remote_cdm, - const base::Optional<base::UnguessableToken>& cdm_id, - mojo::PendingRemote<mojom::Decryptor> decryptor_remote, + media::mojom::CdmContextPtr cdm_context, const SessionMessageCB& session_message_cb, const SessionClosedCB& session_closed_cb, const SessionKeysChangeCB& session_keys_change_cb, const SessionExpirationUpdateCB& session_expiration_update_cb) : remote_cdm_(std::move(remote_cdm)), - cdm_id_(cdm_id), - decryptor_remote_(std::move(decryptor_remote)), + cdm_id_(cdm_context->cdm_id), + decryptor_remote_(std::move(cdm_context->decryptor)), +#if defined(OS_WIN) + requires_media_foundation_renderer_( + cdm_context->requires_media_foundation_renderer), +#endif // defined(OS_WIN) session_message_cb_(session_message_cb), session_closed_cb_(session_closed_cb), session_keys_change_cb_(session_keys_change_cb), session_expiration_update_cb_(session_expiration_update_cb) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); - DCHECK(cdm_id); + DCHECK(cdm_id_); DVLOG(2) << __func__ << " cdm_id: " << CdmContext::CdmIdToString(base::OptionalOrNullptr(cdm_id_)); DCHECK(session_message_cb_); @@ -58,12 +61,6 @@ MojoCdm::MojoCdm(mojo::Remote<mojom::ContentDecryptionModule> remote_cdm, DCHECK(session_keys_change_cb_); DCHECK(session_expiration_update_cb_); -#if defined(OS_WIN) - // TODO(xhwang): Need a way to implement RequiresMediaFoundationRenderer(). - // The plan is to pass back this info when we create the CDM, e.g. in the - // `cdm_created_cb` of `MojoCdmFactory::Create()`. -#endif // defined(OS_WIN) - remote_cdm_->SetClient(client_receiver_.BindNewEndpointAndPassRemote()); // Report a false event here as a baseline. @@ -273,17 +270,17 @@ Decryptor* MojoCdm::GetDecryptor() { base::Optional<base::UnguessableToken> MojoCdm::GetCdmId() const { // Can be called on a different thread. base::AutoLock auto_lock(lock_); - DVLOG(2) << __func__ << ": cdm_id = " + DVLOG(2) << __func__ << ": cdm_id=" << CdmContext::CdmIdToString(base::OptionalOrNullptr(cdm_id_)); return cdm_id_; } #if defined(OS_WIN) bool MojoCdm::RequiresMediaFoundationRenderer() { - DVLOG(2) << __func__ << " this:" << this - << " is_mf_renderer_content_:" << is_mf_renderer_content_; - - return is_mf_renderer_content_; + base::AutoLock auto_lock(lock_); + DVLOG(2) << __func__ << ": requires_media_foundation_renderer_=" + << requires_media_foundation_renderer_; + return requires_media_foundation_renderer_; } #endif // defined(OS_WIN) diff --git a/chromium/media/mojo/clients/mojo_cdm.h b/chromium/media/mojo/clients/mojo_cdm.h index b0f88e5c01c..ca886cc99cf 100644 --- a/chromium/media/mojo/clients/mojo_cdm.h +++ b/chromium/media/mojo/clients/mojo_cdm.h @@ -44,9 +44,9 @@ class MojoCdm final : public ContentDecryptionModule, public: using MessageType = CdmMessageType; + // All parameters must be non-null. MojoCdm(mojo::Remote<mojom::ContentDecryptionModule> remote_cdm, - const base::Optional<base::UnguessableToken>& cdm_id, - mojo::PendingRemote<mojom::Decryptor> decryptor_remote, + media::mojom::CdmContextPtr cdm_context, const SessionMessageCB& session_message_cb, const SessionClosedCB& session_closed_cb, const SessionKeysChangeCB& session_keys_change_cb, @@ -117,26 +117,31 @@ class MojoCdm final : public ContentDecryptionModule, mojo::AssociatedReceiver<ContentDecryptionModuleClient> client_receiver_{ this}; - // Protects |cdm_id_|, |decryptor_remote_|, |decryptor_| and - // |decryptor_task_runner_| which could be accessed from other threads. - // See CdmContext implementation above. + // Protects |cdm_id_|, |decryptor_remote_|, |decryptor_|, + // |decryptor_task_runner_| and |requires_media_foundation_renderer_|, which + // could be accessed from other threads. See CdmContext implementation above. mutable base::Lock lock_; // CDM ID of the remote CDM. Set after initialization is completed. Must not // be invalid if initialization succeeded. - base::Optional<base::UnguessableToken> cdm_id_; + base::Optional<base::UnguessableToken> cdm_id_ GUARDED_BY(lock_); // The mojo::PendingRemote<mojom::Decryptor> exposed by the remote CDM. Set // after initialization is completed and cleared after |decryptor_| is // created. May be invalid after initialization if the CDM doesn't support a // Decryptor. - mojo::PendingRemote<mojom::Decryptor> decryptor_remote_; + mojo::PendingRemote<mojom::Decryptor> decryptor_remote_ GUARDED_BY(lock_); // Decryptor based on |decryptor_remote_|, lazily created in // GetDecryptor(). Since GetDecryptor() can be called on a different thread, // use |decryptor_task_runner_| to bind |decryptor_| to that thread. - std::unique_ptr<MojoDecryptor> decryptor_; - scoped_refptr<base::SingleThreadTaskRunner> decryptor_task_runner_; + std::unique_ptr<MojoDecryptor> decryptor_ GUARDED_BY(lock_); + scoped_refptr<base::SingleThreadTaskRunner> decryptor_task_runner_ + GUARDED_BY(lock_); + +#if defined(OS_WIN) + bool requires_media_foundation_renderer_ GUARDED_BY(lock_) = false; +#endif // defined(OS_WIN) // Callbacks for firing session events. SessionMessageCB session_message_cb_; @@ -152,11 +157,6 @@ class MojoCdm final : public ContentDecryptionModule, CallbackRegistry<EventCB::RunType> event_callbacks_; -#if defined(OS_WIN) - // The current content is for MediaFoundationRenderer or not. - bool is_mf_renderer_content_ = false; -#endif // defined(OS_WIN) - // This must be the last member. base::WeakPtrFactory<MojoCdm> weak_factory_{this}; diff --git a/chromium/media/mojo/clients/mojo_cdm_factory.cc b/chromium/media/mojo/clients/mojo_cdm_factory.cc index 7d95271465a..8e4732a3e9c 100644 --- a/chromium/media/mojo/clients/mojo_cdm_factory.cc +++ b/chromium/media/mojo/clients/mojo_cdm_factory.cc @@ -15,6 +15,7 @@ #include "media/base/key_systems.h" #include "media/cdm/aes_decryptor.h" #include "media/mojo/clients/mojo_cdm.h" +#include "media/mojo/mojom/content_decryption_module.mojom.h" #include "media/mojo/mojom/interface_factory.mojom.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/remote.h" @@ -30,21 +31,20 @@ void OnCdmCreated( const SessionExpirationUpdateCB& session_expiration_update_cb, CdmCreatedCB cdm_created_cb, mojo::PendingRemote<mojom::ContentDecryptionModule> cdm_remote, - const base::Optional<base::UnguessableToken>& cdm_id, - mojo::PendingRemote<mojom::Decryptor> decryptor, + media::mojom::CdmContextPtr cdm_context, const std::string& error_message) { // Convert from a PendingRemote to Remote so we can verify that it is // connected, this will also check if |cdm_remote| is null. mojo::Remote<mojom::ContentDecryptionModule> remote(std::move(cdm_remote)); - if (!remote || !remote.is_connected()) { + if (!remote || !remote.is_connected() || !cdm_context) { std::move(cdm_created_cb).Run(nullptr, error_message); return; } std::move(cdm_created_cb) .Run(base::MakeRefCounted<MojoCdm>( - std::move(remote), cdm_id, std::move(decryptor), - session_message_cb, session_closed_cb, session_keys_change_cb, + std::move(remote), std::move(cdm_context), session_message_cb, + session_closed_cb, session_keys_change_cb, session_expiration_update_cb), ""); } diff --git a/chromium/media/mojo/clients/mojo_cdm_unittest.cc b/chromium/media/mojo/clients/mojo_cdm_unittest.cc index 08e24fb4722..3eb54feb6ed 100644 --- a/chromium/media/mojo/clients/mojo_cdm_unittest.cc +++ b/chromium/media/mojo/clients/mojo_cdm_unittest.cc @@ -28,7 +28,9 @@ using ::testing::_; using ::testing::DoAll; using ::testing::Invoke; +using ::testing::Return; using ::testing::ReturnNull; +using ::testing::ReturnPointee; using ::testing::StrictMock; using ::testing::WithArg; using ::testing::WithArgs; @@ -68,10 +70,17 @@ class MojoCdmTest : public ::testing::Test { }; MojoCdmTest() = default; - ~MojoCdmTest() override = default; void Initialize(ExpectedResult expected_result) { + EXPECT_CALL(*remote_cdm_, GetCdmContext()) + .WillRepeatedly(Return(&cdm_context_)); + EXPECT_CALL(cdm_context_, GetDecryptor()).WillRepeatedly(ReturnNull()); +#if defined(OS_WIN) + EXPECT_CALL(cdm_context_, RequiresMediaFoundationRenderer()) + .WillRepeatedly(ReturnPointee(&requires_media_foundation_renderer_)); +#endif + if (expected_result == CONNECTION_ERROR_DURING) { // Create() will be successful, so provide a callback that will break // the connection before returning the CDM. @@ -79,18 +88,17 @@ class MojoCdmTest : public ::testing::Test { &MojoCdmTest::ForceConnectionError, base::Unretained(this))); } - MojoCdmService::Create( - &cdm_factory_, &mojo_cdm_service_context_, kClearKeyKeySystem, - CdmConfig(), - base::BindOnce(&MojoCdmTest::OnCdmServiceCreated, + mojo_cdm_service_ = + std::make_unique<MojoCdmService>(&mojo_cdm_service_context_); + mojo_cdm_service_->Initialize( + &cdm_factory_, kClearKeyKeySystem, CdmConfig(), + base::BindOnce(&MojoCdmTest::OnCdmServiceInitialized, base::Unretained(this), expected_result)); } - void OnCdmServiceCreated(ExpectedResult expected_result, - std::unique_ptr<MojoCdmService> cdm_service, - mojo::PendingRemote<mojom::Decryptor> decryptor, - const std::string& error_message) { - mojo_cdm_service_ = std::move(cdm_service); + void OnCdmServiceInitialized(ExpectedResult expected_result, + mojom::CdmContextPtr cdm_context, + const std::string& error_message) { cdm_receiver_ = std::make_unique<mojo::Receiver<mojom::ContentDecryptionModule>>( mojo_cdm_service_.get()); @@ -103,8 +111,7 @@ class MojoCdmTest : public ::testing::Test { mojo::Remote<mojom::ContentDecryptionModule> cdm_remote( cdm_receiver_->BindNewPipeAndPassRemote()); mojo_cdm_ = base::MakeRefCounted<MojoCdm>( - std::move(cdm_remote), mojo_cdm_service_->cdm_id(), - std::move(decryptor), + std::move(cdm_remote), std::move(cdm_context), base::BindRepeating(&MockCdmClient::OnSessionMessage, base::Unretained(&cdm_client_)), base::BindRepeating(&MockCdmClient::OnSessionClosed, @@ -113,7 +120,6 @@ class MojoCdmTest : public ::testing::Test { base::Unretained(&cdm_client_)), base::BindRepeating(&MockCdmClient::OnSessionExpirationUpdate, base::Unretained(&cdm_client_))); - remote_cdm_ = cdm_factory_.GetCreatedCdm(); EXPECT_EQ(kClearKeyKeySystem, remote_cdm_->GetKeySystem()); base::RunLoop().RunUntilIdle(); } @@ -349,8 +355,9 @@ class MojoCdmTest : public ::testing::Test { base::TestMessageLoop message_loop_; // |remote_cdm_| represents the CDM at the end of the mojo message pipe. - MockCdm* remote_cdm_; - MockCdmFactory cdm_factory_; + scoped_refptr<MockCdm> remote_cdm_{new MockCdm()}; + MockCdmFactory cdm_factory_{remote_cdm_}; + MockCdmContext cdm_context_; MojoCdmServiceContext mojo_cdm_service_context_; StrictMock<MockCdmClient> cdm_client_; @@ -363,6 +370,10 @@ class MojoCdmTest : public ::testing::Test { std::unique_ptr<mojo::Receiver<mojom::ContentDecryptionModule>> cdm_receiver_; scoped_refptr<ContentDecryptionModule> mojo_cdm_; +#if defined(OS_WIN) + bool requires_media_foundation_renderer_ = false; +#endif + private: DISALLOW_COPY_AND_ASSIGN(MojoCdmTest); }; @@ -596,9 +607,6 @@ TEST_F(MojoCdmTest, SessionKeysChangeCB_Success) { base::RunLoop().RunUntilIdle(); } -// TODO(xhwang): Refactor MockCdmFactory to mock CdmFactory::Create() so that we -// can set expectations and default actions on the created MockCdm, e.g. return -// a non-null Decryptor to test the HasDecryptor case. TEST_F(MojoCdmTest, NoDecryptor) { Initialize(SUCCESS); auto* cdm_context = mojo_cdm_->GetCdmContext(); @@ -607,4 +615,22 @@ TEST_F(MojoCdmTest, NoDecryptor) { EXPECT_FALSE(decryptor); } +#if defined(OS_WIN) +TEST_F(MojoCdmTest, RequiresMediaFoundationRenderer) { + requires_media_foundation_renderer_ = true; + Initialize(SUCCESS); + auto* cdm_context = mojo_cdm_->GetCdmContext(); + EXPECT_TRUE(cdm_context) << "All CDMs should support CdmContext"; + EXPECT_TRUE(cdm_context->RequiresMediaFoundationRenderer()); +} + +TEST_F(MojoCdmTest, NotRequireMediaFoundationRenderer) { + requires_media_foundation_renderer_ = false; + Initialize(SUCCESS); + auto* cdm_context = mojo_cdm_->GetCdmContext(); + EXPECT_TRUE(cdm_context) << "All CDMs should support CdmContext"; + EXPECT_FALSE(cdm_context->RequiresMediaFoundationRenderer()); +} +#endif + } // namespace media diff --git a/chromium/media/mojo/clients/mojo_decryptor_unittest.cc b/chromium/media/mojo/clients/mojo_decryptor_unittest.cc index fa9638f6245..bd1d63a3408 100644 --- a/chromium/media/mojo/clients/mojo_decryptor_unittest.cc +++ b/chromium/media/mojo/clients/mojo_decryptor_unittest.cc @@ -42,10 +42,10 @@ class MojoDecryptorTest : public ::testing::Test { void SetWriterCapacity(uint32_t capacity) { writer_capacity_ = capacity; } void Initialize() { - decryptor_.reset(new StrictMock<MockDecryptor>()); + decryptor_ = std::make_unique<StrictMock<MockDecryptor>>(); - mojo_decryptor_service_.reset( - new MojoDecryptorService(decryptor_.get(), nullptr)); + mojo_decryptor_service_ = + std::make_unique<MojoDecryptorService>(decryptor_.get(), nullptr); receiver_ = std::make_unique<mojo::Receiver<mojom::Decryptor>>( mojo_decryptor_service_.get()); diff --git a/chromium/media/mojo/clients/mojo_renderer_unittest.cc b/chromium/media/mojo/clients/mojo_renderer_unittest.cc index 0211d5ccee2..831017c1355 100644 --- a/chromium/media/mojo/clients/mojo_renderer_unittest.cc +++ b/chromium/media/mojo/clients/mojo_renderer_unittest.cc @@ -4,6 +4,8 @@ #include <stdint.h> +#include <memory> + #include "base/bind.h" #include "base/macros.h" #include "base/memory/ptr_util.h" @@ -72,10 +74,10 @@ class MojoRendererTest : public ::testing::Test { &mojo_cdm_service_context_, std::move(mock_renderer), remote_renderer_remote.InitWithNewPipeAndPassReceiver()); - mojo_renderer_.reset( - new MojoRenderer(message_loop_.task_runner(), - std::unique_ptr<VideoOverlayFactory>(nullptr), nullptr, - std::move(remote_renderer_remote))); + mojo_renderer_ = std::make_unique<MojoRenderer>( + message_loop_.task_runner(), + std::unique_ptr<VideoOverlayFactory>(nullptr), nullptr, + std::move(remote_renderer_remote)); // CreateAudioStream() and CreateVideoStream() overrides expectations for // expected non-NULL streams. @@ -168,19 +170,17 @@ class MojoRendererTest : public ::testing::Test { base::RunLoop().RunUntilIdle(); } - void OnCdmServiceCreated(std::unique_ptr<MojoCdmService> cdm_service, - mojo::PendingRemote<mojom::Decryptor> decryptor, - const std::string& error_message) { - EXPECT_TRUE(!!cdm_service); - cdm_context_.set_cdm_id(base::OptionalOrNullptr(cdm_service->cdm_id())); - mojo_cdm_service_ = std::move(cdm_service); + void OnCdmServiceInitialized(mojom::CdmContextPtr cdm_context, + const std::string& error_message) { + cdm_context_.set_cdm_id(cdm_context->cdm_id); } void CreateCdm() { - MojoCdmService::Create( - &cdm_factory_, &mojo_cdm_service_context_, kClearKeyKeySystem, - CdmConfig(), - base::BindOnce(&MojoRendererTest::OnCdmServiceCreated, + mojo_cdm_service_ = + std::make_unique<MojoCdmService>(&mojo_cdm_service_context_); + mojo_cdm_service_->Initialize( + &cdm_factory_, kClearKeyKeySystem, CdmConfig(), + base::BindOnce(&MojoRendererTest::OnCdmServiceInitialized, base::Unretained(this))); base::RunLoop().RunUntilIdle(); } @@ -304,8 +304,7 @@ TEST_F(MojoRendererTest, SetCdm_InvalidCdmId) { TEST_F(MojoRendererTest, SetCdm_NonExistCdmId) { Initialize(); - auto cdm_id = base::UnguessableToken::Create(); - cdm_context_.set_cdm_id(&cdm_id); + cdm_context_.set_cdm_id(base::UnguessableToken::Create()); SetCdmAndExpect(false); } diff --git a/chromium/media/mojo/clients/mojo_video_decoder.cc b/chromium/media/mojo/clients/mojo_video_decoder.cc index a093a377cd6..23c3bc5d7c1 100644 --- a/chromium/media/mojo/clients/mojo_video_decoder.cc +++ b/chromium/media/mojo/clients/mojo_video_decoder.cc @@ -147,10 +147,6 @@ VideoDecoderType MojoVideoDecoder::GetDecoderType() const { return decoder_type_; } -std::string MojoVideoDecoder::GetDisplayName() const { - return "MojoVideoDecoder"; -} - void MojoVideoDecoder::FailInit(InitCB init_cb, Status err) { task_runner_->PostTask(FROM_HERE, base::BindOnce(std::move(init_cb), std::move(err))); diff --git a/chromium/media/mojo/clients/mojo_video_decoder.h b/chromium/media/mojo/clients/mojo_video_decoder.h index b5fdef8375d..1d85f48837d 100644 --- a/chromium/media/mojo/clients/mojo_video_decoder.h +++ b/chromium/media/mojo/clients/mojo_video_decoder.h @@ -60,7 +60,6 @@ class MojoVideoDecoder final : public VideoDecoder, // Decoder implementation bool IsPlatformDecoder() const final; bool SupportsDecryption() const final; - std::string GetDisplayName() const override; VideoDecoderType GetDecoderType() const final; // VideoDecoder implementation. diff --git a/chromium/media/mojo/clients/mojo_video_encode_accelerator.cc b/chromium/media/mojo/clients/mojo_video_encode_accelerator.cc index 2fdfdef3ba4..192c2c31ca0 100644 --- a/chromium/media/mojo/clients/mojo_video_encode_accelerator.cc +++ b/chromium/media/mojo/clients/mojo_video_encode_accelerator.cc @@ -134,18 +134,7 @@ void MojoVideoEncodeAccelerator::Encode(scoped_refptr<VideoFrame> frame, DCHECK_EQ(num_planes, frame->layout().num_planes()); DCHECK(vea_.is_bound()); -#if defined(OS_LINUX) || defined(OS_CHROMEOS) - // TODO(crbug.com/1003197): Remove this once we stop supporting STORAGE_DMABUF - // in VideoEncodeAccelerator. - if (frame->storage_type() == VideoFrame::STORAGE_DMABUFS) { - DCHECK(frame->HasDmaBufs()); - vea_->Encode( - frame, force_keyframe, - base::BindOnce(base::DoNothing::Once<scoped_refptr<VideoFrame>>(), - frame)); - return; - } -#endif + // GPU memory path: Pass-through. if (frame->storage_type() == VideoFrame::STORAGE_GPU_MEMORY_BUFFER) { vea_->Encode( frame, force_keyframe, @@ -154,62 +143,26 @@ void MojoVideoEncodeAccelerator::Encode(scoped_refptr<VideoFrame> frame, return; } - if ((frame->format() != PIXEL_FORMAT_I420 && - frame->format() != PIXEL_FORMAT_NV12) || - VideoFrame::STORAGE_SHMEM != frame->storage_type() || - !frame->shm_region()->IsValid()) { - DLOG(ERROR) << "Unexpected video frame buffer"; - return; - } - - // Oftentimes |frame|'s underlying planes will be aligned and not tightly - // packed, so don't use VideoFrame::AllocationSize(). - const size_t allocation_size = frame->shm_region()->GetSize(); - - // A MojoSharedBufferVideoFrame is created with an owned writable handle. As - // the handle in |frame| is not owned, a new region must be created and - // |frame| copied into it. - mojo::ScopedSharedBufferHandle dst_handle = - mojo::SharedBufferHandle::Create(allocation_size); - if (!dst_handle->is_valid()) { - DLOG(ERROR) << "Can't create new frame backing memory"; - return; - } - mojo::ScopedSharedBufferMapping dst_mapping = - dst_handle->Map(allocation_size); - if (!dst_mapping) { - DLOG(ERROR) << "Can't map new frame backing memory"; + // Mappable memory path: Copy buffer to shared memory. + if (frame->format() != PIXEL_FORMAT_I420 && + frame->format() != PIXEL_FORMAT_NV12) { + DLOG(ERROR) << "Unexpected pixel format: " + << VideoPixelFormatToString(frame->format()); return; } - DCHECK(frame->shm_region()); - base::WritableSharedMemoryMapping src_mapping = frame->shm_region()->Map(); - if (!src_mapping.IsValid()) { - DLOG(ERROR) << "Can't map src frame backing memory"; + if (frame->storage_type() != VideoFrame::STORAGE_SHMEM && + frame->storage_type() != VideoFrame::STORAGE_UNOWNED_MEMORY) { + DLOG(ERROR) << "Unexpected storage type: " + << VideoFrame::StorageTypeToString(frame->storage_type()); return; } - memcpy(dst_mapping.get(), src_mapping.memory(), allocation_size); - std::vector<uint32_t> offsets(num_planes); - std::vector<int32_t> strides(num_planes); - for (size_t i = 0; i < num_planes; ++i) { - offsets[i] = frame->data(i) - frame->data(0); - strides[i] = frame->stride(i); - } - - // Temporary Mojo VideoFrame to allow for marshalling. scoped_refptr<MojoSharedBufferVideoFrame> mojo_frame = - MojoSharedBufferVideoFrame::Create( - frame->format(), frame->coded_size(), frame->visible_rect(), - frame->natural_size(), std::move(dst_handle), allocation_size, - std::move(offsets), std::move(strides), frame->timestamp()); + MojoSharedBufferVideoFrame::CreateFromYUVFrame(*frame); if (!mojo_frame) { - DLOG(ERROR) << "Failed creating MojoSharedBufferVideoFrame"; + DLOG(ERROR) << "Failed creating MojoSharedBufferVideoFrame from YUV"; return; } - - // Encode() is synchronous: clients will assume full ownership of |frame| when - // this gets destroyed and probably recycle its shared_memory_handle(): keep - // the former alive until the remote end is actually finished. vea_->Encode( std::move(mojo_frame), force_keyframe, base::BindOnce(base::DoNothing::Once<scoped_refptr<VideoFrame>>(), diff --git a/chromium/media/mojo/clients/win/media_foundation_renderer_client.cc b/chromium/media/mojo/clients/win/media_foundation_renderer_client.cc index 3bb5f2d15a7..66ef3880041 100644 --- a/chromium/media/mojo/clients/win/media_foundation_renderer_client.cc +++ b/chromium/media/mojo/clients/win/media_foundation_renderer_client.cc @@ -84,19 +84,20 @@ void MediaFoundationRendererClient::OnConnectionError() { void MediaFoundationRendererClient::OnRemoteRendererInitialized( PipelineStatus status) { DVLOG_FUNC(1) << "status=" << status; - DCHECK(media_task_runner_->BelongsToCurrentThread()); + DCHECK(!init_cb_.is_null()); + if (status != media::PipelineStatus::PIPELINE_OK) { - DCHECK(!init_cb_.is_null()); std::move(init_cb_).Run(status); return; } if (has_video_) { // TODO(frankli): Add code to init DCOMPTextureWrapper. - } else { - std::move(init_cb_).Run(status); + NOTIMPLEMENTED() << "Video compositing not implemented yet"; } + + std::move(init_cb_).Run(status); } void MediaFoundationRendererClient::OnDCOMPSurfaceHandleCreated(bool success) { @@ -385,7 +386,7 @@ void MediaFoundationRendererClient::OnVideoFrameRateChange( scoped_refptr<media::VideoFrame> MediaFoundationRendererClient::Render( base::TimeTicks deadline_min, base::TimeTicks deadline_max, - bool background_rendering) { + RenderingMode mode) { // Returns no video frame as it is rendered independently by Windows Direct // Composition. return nullptr; diff --git a/chromium/media/mojo/clients/win/media_foundation_renderer_client.h b/chromium/media/mojo/clients/win/media_foundation_renderer_client.h index 7ba6d844dea..f9afedaa4f7 100644 --- a/chromium/media/mojo/clients/win/media_foundation_renderer_client.h +++ b/chromium/media/mojo/clients/win/media_foundation_renderer_client.h @@ -80,9 +80,10 @@ class MediaFoundationRendererClient void OnVideoFrameRateChange(base::Optional<int>) override; // media::VideoRendererSink::RenderCallback implementation. - scoped_refptr<media::VideoFrame> Render(base::TimeTicks deadline_min, - base::TimeTicks deadline_max, - bool background_rendering) override; + scoped_refptr<media::VideoFrame> Render( + base::TimeTicks deadline_min, + base::TimeTicks deadline_max, + RenderingMode rendering_mode) override; void OnFrameDropped() override; base::TimeDelta GetPreferredRenderInterval() override; |