Commit 109230ec authored by Jose Lopes's avatar Jose Lopes Committed by Commit Bot

media: Migrate Decryptor decoder init callback.

The callback is called once to indicate the initialization is complete:
* https://cs.chromium.org/chromium/src/media/base/decryptor.h?rcl=bf6cbdd206196a39ecce5575a8a828eaa844dcb5&l=92

The initialization operations are defined in:
* https://cs.chromium.org/chromium/src/media/base/decryptor.h?rcl=bf6cbdd206196a39ecce5575a8a828eaa844dcb5&l=98

This is part of the base::Callback migration.

Context: https://cs.chromium.org/chromium/src/docs/callback.md?rcl=9fcc3764aea8f97e9f6de4a9ee61d554e67edcda&l=40

Bug: 714018
Change-Id: I7a2f3245f6d03eeed83c79a6155f1678aae136d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050588
Commit-Queue: Jose Lopes <jabolopes@google.com>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743894}
parent 55e8f04d
......@@ -94,14 +94,14 @@ class MEDIA_EXPORT Decryptor {
//
// First Parameter: Indicates initialization success.
// - Set to true if initialization was successful. False if an error occurred.
typedef base::Callback<void(bool)> DecoderInitCB;
using DecoderInitCB = base::OnceCallback<void(bool)>;
// Initializes a decoder with the given |config|, executing the |init_cb|
// upon completion.
virtual void InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) = 0;
DecoderInitCB init_cb) = 0;
virtual void InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) = 0;
DecoderInitCB init_cb) = 0;
// Helper structure for managing multiple decoded audio buffers per input.
typedef std::list<scoped_refptr<AudioBuffer> > AudioFrames;
......
......@@ -496,11 +496,9 @@ class MockDecryptor : public Decryptor {
DecryptCB decrypt_cb));
MOCK_METHOD1(CancelDecrypt, void(StreamType stream_type));
MOCK_METHOD2(InitializeAudioDecoder,
void(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb));
void(const AudioDecoderConfig& config, DecoderInitCB init_cb));
MOCK_METHOD2(InitializeVideoDecoder,
void(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb));
void(const VideoDecoderConfig& config, DecoderInitCB init_cb));
MOCK_METHOD2(DecryptAndDecodeAudio,
void(scoped_refptr<DecoderBuffer> encrypted,
const AudioDecodeCB& audio_decode_cb));
......
......@@ -524,15 +524,15 @@ void AesDecryptor::CancelDecrypt(StreamType stream_type) {
}
void AesDecryptor::InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) {
DecoderInitCB init_cb) {
// AesDecryptor does not support audio decoding.
init_cb.Run(false);
std::move(init_cb).Run(false);
}
void AesDecryptor::InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) {
DecoderInitCB init_cb) {
// AesDecryptor does not support video decoding.
init_cb.Run(false);
std::move(init_cb).Run(false);
}
void AesDecryptor::DecryptAndDecodeAudio(scoped_refptr<DecoderBuffer> encrypted,
......
......@@ -74,9 +74,9 @@ class MEDIA_EXPORT AesDecryptor : public ContentDecryptionModule,
DecryptCB decrypt_cb) override;
void CancelDecrypt(StreamType stream_type) override;
void InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) override;
DecoderInitCB init_cb) override;
void InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) override;
DecoderInitCB init_cb) override;
void DecryptAndDecodeAudio(scoped_refptr<DecoderBuffer> encrypted,
const AudioDecodeCB& audio_decode_cb) override;
void DecryptAndDecodeVideo(scoped_refptr<DecoderBuffer> encrypted,
......
......@@ -238,9 +238,9 @@ CdmAdapter::~CdmAdapter() {
cdm_promise_adapter_.Clear();
if (audio_init_cb_)
audio_init_cb_.Run(false);
std::move(audio_init_cb_).Run(false);
if (video_init_cb_)
video_init_cb_.Run(false);
std::move(video_init_cb_).Run(false);
}
CdmWrapper* CdmAdapter::CreateCdmInstance(const std::string& key_system) {
......@@ -494,7 +494,7 @@ void CdmAdapter::CancelDecrypt(StreamType stream_type) {
}
void CdmAdapter::InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) {
DecoderInitCB init_cb) {
DVLOG(2) << __func__ << ": " << config.AsHumanReadableString();
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(!audio_init_cb_);
......@@ -504,7 +504,7 @@ void CdmAdapter::InitializeAudioDecoder(const AudioDecoderConfig& config,
if (cdm_config.codec == cdm::kUnknownAudioCodec) {
DVLOG(1) << __func__
<< ": Unsupported config: " << config.AsHumanReadableString();
init_cb.Run(false);
std::move(init_cb).Run(false);
return;
}
......@@ -512,7 +512,7 @@ void CdmAdapter::InitializeAudioDecoder(const AudioDecoderConfig& config,
if (status != cdm::kSuccess && status != cdm::kDeferredInitialization) {
DCHECK(status == cdm::kInitializationError);
DVLOG(1) << __func__ << ": status = " << status;
init_cb.Run(false);
std::move(init_cb).Run(false);
return;
}
......@@ -521,15 +521,15 @@ void CdmAdapter::InitializeAudioDecoder(const AudioDecoderConfig& config,
if (status == cdm::kDeferredInitialization) {
DVLOG(1) << "Deferred initialization in " << __func__;
audio_init_cb_ = init_cb;
audio_init_cb_ = std::move(init_cb);
return;
}
init_cb.Run(true);
std::move(init_cb).Run(true);
}
void CdmAdapter::InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) {
DecoderInitCB init_cb) {
DVLOG(2) << __func__ << ": " << config.AsHumanReadableString();
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK(!video_init_cb_);
......@@ -539,7 +539,7 @@ void CdmAdapter::InitializeVideoDecoder(const VideoDecoderConfig& config,
if (config.alpha_mode() != VideoDecoderConfig::AlphaMode::kIsOpaque) {
DVLOG(1) << __func__
<< ": Unsupported config: " << config.AsHumanReadableString();
init_cb.Run(false);
std::move(init_cb).Run(false);
return;
}
......@@ -550,7 +550,7 @@ void CdmAdapter::InitializeVideoDecoder(const VideoDecoderConfig& config,
if (cdm_config.codec == cdm::kUnknownVideoCodec) {
DVLOG(1) << __func__
<< ": Unsupported config: " << config.AsHumanReadableString();
init_cb.Run(false);
std::move(init_cb).Run(false);
return;
}
......@@ -558,7 +558,7 @@ void CdmAdapter::InitializeVideoDecoder(const VideoDecoderConfig& config,
if (status != cdm::kSuccess && status != cdm::kDeferredInitialization) {
DCHECK(status == cdm::kInitializationError);
DVLOG(1) << __func__ << ": status = " << status;
init_cb.Run(false);
std::move(init_cb).Run(false);
return;
}
......@@ -567,11 +567,11 @@ void CdmAdapter::InitializeVideoDecoder(const VideoDecoderConfig& config,
if (status == cdm::kDeferredInitialization) {
DVLOG(1) << "Deferred initialization in " << __func__;
video_init_cb_ = init_cb;
video_init_cb_ = std::move(init_cb);
return;
}
init_cb.Run(true);
std::move(init_cb).Run(true);
}
void CdmAdapter::DecryptAndDecodeAudio(scoped_refptr<DecoderBuffer> encrypted,
......
......@@ -103,9 +103,9 @@ class MEDIA_EXPORT CdmAdapter : public ContentDecryptionModule,
DecryptCB decrypt_cb) final;
void CancelDecrypt(StreamType stream_type) final;
void InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) final;
DecoderInitCB init_cb) final;
void InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) final;
DecoderInitCB init_cb) final;
void DecryptAndDecodeAudio(scoped_refptr<DecoderBuffer> encrypted,
const AudioDecodeCB& audio_decode_cb) final;
void DecryptAndDecodeVideo(scoped_refptr<DecoderBuffer> encrypted,
......
......@@ -27,6 +27,7 @@
#endif // !defined(OS_ANDROID)
using ::base::test::RunCallback;
using ::base::test::RunOnceCallback;
using ::testing::_;
using ::testing::IsNull;
using ::testing::NiceMock;
......@@ -232,11 +233,13 @@ class DecoderSelectorTest : public ::testing::Test {
switch (TypeParam::kStreamType) {
case DemuxerStream::AUDIO:
EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
.WillRepeatedly(RunCallback<1>(capability == kDecryptAndDecode));
.WillRepeatedly(
RunOnceCallback<1>(capability == kDecryptAndDecode));
break;
case DemuxerStream::VIDEO:
EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
.WillRepeatedly(RunCallback<1>(capability == kDecryptAndDecode));
.WillRepeatedly(
RunOnceCallback<1>(capability == kDecryptAndDecode));
break;
default:
NOTREACHED();
......
......@@ -24,6 +24,7 @@
#include "testing/gmock/include/gmock/gmock.h"
using ::base::test::RunCallback;
using ::base::test::RunOnceCallback;
using ::testing::_;
using ::testing::AtMost;
using ::testing::Return;
......@@ -102,7 +103,7 @@ class DecryptingAudioDecoderTest : public testing::Test {
SetCdmType(CDM_WITH_DECRYPTOR);
EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
.Times(AtMost(1))
.WillOnce(RunCallback<1>(true));
.WillOnce(RunOnceCallback<1>(true));
EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
.WillOnce(SaveArg<1>(&key_added_cb_));
......@@ -117,7 +118,7 @@ class DecryptingAudioDecoderTest : public testing::Test {
void ReinitializeConfigChange(const AudioDecoderConfig& new_config) {
EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio));
EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
.WillOnce(RunCallback<1>(true));
.WillOnce(RunOnceCallback<1>(true));
EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
.WillOnce(SaveArg<1>(&key_added_cb_));
decoder_->Initialize(new_config, cdm_context_.get(),
......@@ -285,7 +286,7 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) {
TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) {
SetCdmType(CDM_WITH_DECRYPTOR);
EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
.WillOnce(RunCallback<1>(false));
.WillOnce(RunOnceCallback<1>(false));
AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
CHANNEL_LAYOUT_STEREO, kSampleRate,
......@@ -356,7 +357,7 @@ TEST_F(DecryptingAudioDecoderTest, Reinitialize_EncryptedToEncrypted) {
EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
.Times(AtMost(1))
.WillOnce(RunCallback<1>(true));
.WillOnce(RunOnceCallback<1>(true));
// The new config is different from the initial config in bits-per-channel,
// channel layout and samples_per_second.
......@@ -378,7 +379,7 @@ TEST_F(DecryptingAudioDecoderTest, Reinitialize_EncryptedToClear) {
EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
.Times(AtMost(1))
.WillOnce(RunCallback<1>(true));
.WillOnce(RunOnceCallback<1>(true));
// The new config is different from the initial config in bits-per-channel,
// channel layout and samples_per_second.
......
......@@ -23,11 +23,13 @@
#include "testing/gmock/include/gmock/gmock.h"
using ::base::test::RunCallback;
using ::base::test::RunOnceCallback;
using ::testing::_;
using ::testing::Invoke;
using ::testing::Return;
using ::testing::SaveArg;
using ::testing::StrictMock;
using ::testing::WithArg;
namespace media {
......@@ -89,7 +91,7 @@ class DecryptingVideoDecoderTest : public testing::Test {
void Initialize() {
SetCdmType(CDM_WITH_DECRYPTOR);
EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
.WillOnce(RunCallback<1>(true));
.WillOnce(RunOnceCallback<1>(true));
EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kVideo, _))
.WillOnce(SaveArg<1>(&key_added_cb_));
......@@ -100,7 +102,7 @@ class DecryptingVideoDecoderTest : public testing::Test {
void Reinitialize(const VideoDecoderConfig& new_config) {
EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kVideo));
EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
.WillOnce(RunCallback<1>(true));
.WillOnce(RunOnceCallback<1>(true));
EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kVideo, _))
.WillOnce(SaveArg<1>(&key_added_cb_));
......@@ -256,7 +258,7 @@ TEST_F(DecryptingVideoDecoderTest, Initialize_CdmWithoutDecryptor) {
TEST_F(DecryptingVideoDecoderTest, Initialize_Failure) {
SetCdmType(CDM_WITH_DECRYPTOR);
EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
.WillRepeatedly(RunCallback<1>(false));
.WillRepeatedly(RunOnceCallback<1>(false));
EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kVideo, _))
.WillRepeatedly(SaveArg<1>(&key_added_cb_));
......@@ -282,7 +284,7 @@ TEST_F(DecryptingVideoDecoderTest, Reinitialize_Failure) {
EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kVideo));
EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
.WillOnce(RunCallback<1>(false));
.WillOnce(RunOnceCallback<1>(false));
// Reinitialize() expects the reinitialization to succeed. Call
// InitializeAndExpectResult() directly to test the reinitialization failure.
......@@ -406,7 +408,9 @@ TEST_F(DecryptingVideoDecoderTest, Reset_AfterReset) {
TEST_F(DecryptingVideoDecoderTest, Destroy_DuringPendingDecoderInit) {
SetCdmType(CDM_WITH_DECRYPTOR);
EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
.WillOnce(SaveArg<1>(&pending_init_cb_));
.WillOnce(WithArg<1>(Invoke([&](Decryptor::DecoderInitCB init_cb) {
pending_init_cb_ = std::move(init_cb);
})));
InitializeAndExpectResult(TestVideoConfig::NormalEncrypted(), false);
EXPECT_FALSE(!pending_init_cb_);
......
......@@ -27,6 +27,7 @@
#endif
using ::base::test::RunCallback;
using ::base::test::RunOnceCallback;
using ::testing::_;
using ::testing::AnyNumber;
using ::testing::Assign;
......@@ -104,7 +105,7 @@ class VideoDecoderStreamTest
// Decryptor can only decrypt (not decrypt-and-decode) so that
// DecryptingDemuxerStream will be used.
EXPECT_CALL(*decryptor_, InitializeVideoDecoder(_, _))
.WillRepeatedly(RunCallback<1>(false));
.WillRepeatedly(RunOnceCallback<1>(false));
EXPECT_CALL(*decryptor_, Decrypt(_, _, _))
.WillRepeatedly(Invoke(this, &VideoDecoderStreamTest::Decrypt));
}
......
......@@ -59,15 +59,15 @@ void FuchsiaDecryptor::CancelDecrypt(StreamType stream_type) {
}
void FuchsiaDecryptor::InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) {
DecoderInitCB init_cb) {
// Only decryption is supported.
init_cb.Run(false);
std::move(init_cb).Run(false);
}
void FuchsiaDecryptor::InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) {
DecoderInitCB init_cb) {
// Only decryption is supported.
init_cb.Run(false);
std::move(init_cb).Run(false);
}
void FuchsiaDecryptor::DecryptAndDecodeAudio(
......
......@@ -39,9 +39,9 @@ class FuchsiaDecryptor : public Decryptor {
DecryptCB decrypt_cb) override;
void CancelDecrypt(StreamType stream_type) override;
void InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) override;
DecoderInitCB init_cb) override;
void InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) override;
DecoderInitCB init_cb) override;
void DecryptAndDecodeAudio(scoped_refptr<DecoderBuffer> encrypted,
const AudioDecodeCB& audio_decode_cb) override;
void DecryptAndDecodeVideo(scoped_refptr<DecoderBuffer> encrypted,
......
......@@ -212,15 +212,15 @@ void D3D11Decryptor::CancelDecrypt(StreamType stream_type) {
}
void D3D11Decryptor::InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) {
DecoderInitCB init_cb) {
// D3D11Decryptor does not support audio decoding.
init_cb.Run(false);
std::move(init_cb).Run(false);
}
void D3D11Decryptor::InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) {
DecoderInitCB init_cb) {
// D3D11Decryptor does not support video decoding.
init_cb.Run(false);
std::move(init_cb).Run(false);
}
void D3D11Decryptor::DecryptAndDecodeAudio(
......
......@@ -29,9 +29,9 @@ class MEDIA_GPU_EXPORT D3D11Decryptor : public Decryptor {
DecryptCB decrypt_cb) final;
void CancelDecrypt(StreamType stream_type) final;
void InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) final;
DecoderInitCB init_cb) final;
void InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) final;
DecoderInitCB init_cb) final;
void DecryptAndDecodeAudio(scoped_refptr<DecoderBuffer> encrypted,
const AudioDecodeCB& audio_decode_cb) final;
void DecryptAndDecodeVideo(scoped_refptr<DecoderBuffer> encrypted,
......
......@@ -134,23 +134,23 @@ void MojoDecryptor::CancelDecrypt(StreamType stream_type) {
}
void MojoDecryptor::InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) {
DecoderInitCB init_cb) {
DVLOG(1) << __func__;
DCHECK(thread_checker_.CalledOnValidThread());
remote_decryptor_->InitializeAudioDecoder(
config, mojo::WrapCallbackWithDefaultInvokeIfNotRun(
ToOnceCallback(init_cb), false));
config,
mojo::WrapCallbackWithDefaultInvokeIfNotRun(std::move(init_cb), false));
}
void MojoDecryptor::InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) {
DecoderInitCB init_cb) {
DVLOG(1) << __func__;
DCHECK(thread_checker_.CalledOnValidThread());
remote_decryptor_->InitializeVideoDecoder(
config, mojo::WrapCallbackWithDefaultInvokeIfNotRun(
ToOnceCallback(init_cb), false));
config,
mojo::WrapCallbackWithDefaultInvokeIfNotRun(std::move(init_cb), false));
}
void MojoDecryptor::DecryptAndDecodeAudio(
......
......@@ -40,9 +40,9 @@ class MojoDecryptor : public Decryptor {
DecryptCB decrypt_cb) final;
void CancelDecrypt(StreamType stream_type) final;
void InitializeAudioDecoder(const AudioDecoderConfig& config,
const DecoderInitCB& init_cb) final;
DecoderInitCB init_cb) final;
void InitializeVideoDecoder(const VideoDecoderConfig& config,
const DecoderInitCB& init_cb) final;
DecoderInitCB init_cb) final;
void DecryptAndDecodeAudio(scoped_refptr<DecoderBuffer> encrypted,
const AudioDecodeCB& audio_decode_cb) final;
void DecryptAndDecodeVideo(scoped_refptr<DecoderBuffer> encrypted,
......@@ -61,7 +61,6 @@ class MojoDecryptor : public Decryptor {
// TODO(xhwang): Update Decryptor to use OnceCallback. The change is easy,
// but updating tests is hard given gmock doesn't support move-only types.
// See http://crbug.com/751838
using DecoderInitOnceCB = base::OnceCallback<DecoderInitCB::RunType>;
using AudioDecodeOnceCB = base::OnceCallback<AudioDecodeCB::RunType>;
using VideoDecodeOnceCB = base::OnceCallback<VideoDecodeCB::RunType>;
......
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