-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "media/filters/decrypting_audio_decoder.h"
+
#include <stdint.h>
#include <string>
#include "base/bind.h"
#include "base/callback_helpers.h"
-#include "base/cxx17_backports.h"
#include "base/run_loop.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/gmock_move_support.h"
#include "media/base/mock_filters.h"
#include "media/base/test_helpers.h"
#include "media/base/timestamp_constants.h"
-#include "media/filters/decrypting_audio_decoder.h"
#include "testing/gmock/include/gmock/gmock.h"
using ::base::test::RunOnceCallback;
scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(buffer_size));
buffer->set_decrypt_config(DecryptConfig::CreateCencConfig(
std::string(reinterpret_cast<const char*>(kFakeKeyId),
- base::size(kFakeKeyId)),
- std::string(reinterpret_cast<const char*>(kFakeIv), base::size(kFakeIv)),
+ std::size(kFakeKeyId)),
+ std::string(reinterpret_cast<const char*>(kFakeIv), std::size(kFakeIv)),
std::vector<SubsampleEntry>()));
return buffer;
}
decoded_frame_(nullptr),
decoded_frame_list_() {}
+ DecryptingAudioDecoderTest(const DecryptingAudioDecoderTest&) = delete;
+ DecryptingAudioDecoderTest& operator=(const DecryptingAudioDecoderTest&) =
+ delete;
+
~DecryptingAudioDecoderTest() override { Destroy(); }
void InitializeAndExpectResult(const AudioDecoderConfig& config,
decoder_->Initialize(
config, cdm_context_.get(),
base::BindOnce(
- [](bool success, Status status) {
+ [](bool success, DecoderStatus status) {
EXPECT_EQ(status.is_ok(), success);
},
success),
return std::make_unique<CallbackRegistration>();
});
- config_.Initialize(kCodecVorbis, kSampleFormatPlanarF32,
+ config_.Initialize(AudioCodec::kVorbis, kSampleFormatPlanarF32,
CHANNEL_LAYOUT_STEREO, kSampleRate, EmptyExtraData(),
EncryptionScheme::kCenc, base::TimeDelta(), 0);
InitializeAndExpectResult(config_, true);
.WillOnce(RunOnceCallback<1>(true));
decoder_->Initialize(
new_config, cdm_context_.get(),
- base::BindOnce([](Status status) { EXPECT_TRUE(status.is_ok()); }),
+ base::BindOnce(
+ [](DecoderStatus status) { EXPECT_TRUE(status.is_ok()); }),
base::BindRepeating(&DecryptingAudioDecoderTest::FrameReady,
base::Unretained(this)),
base::BindRepeating(&DecryptingAudioDecoderTest::OnWaiting,
}
// Decode |buffer| and expect DecodeDone to get called with |status|.
- void DecodeAndExpect(scoped_refptr<DecoderBuffer> buffer, StatusCode status) {
+ void DecodeAndExpect(scoped_refptr<DecoderBuffer> buffer,
+ DecoderStatus status) {
EXPECT_CALL(*this, DecodeDone(HasStatusCode(status)));
decoder_->Decode(buffer,
base::BindOnce(&DecryptingAudioDecoderTest::DecodeDone,
Invoke(this, &DecryptingAudioDecoderTest::DecryptAndDecodeAudio));
EXPECT_CALL(*this, FrameReady(decoded_frame_));
for (int i = 0; i < kDecodingDelay + 1; ++i)
- DecodeAndExpect(encrypted_buffer_, DecodeStatus::OK);
+ DecodeAndExpect(encrypted_buffer_, DecoderStatus::Codes::kOk);
}
// Sets up expectations and actions to put DecryptingAudioDecoder in an end
void EnterEndOfStreamState() {
// The codec in the |decryptor_| will be flushed.
EXPECT_CALL(*this, FrameReady(decoded_frame_)).Times(kDecodingDelay);
- DecodeAndExpect(DecoderBuffer::CreateEOSBuffer(), DecodeStatus::OK);
+ DecodeAndExpect(DecoderBuffer::CreateEOSBuffer(),
+ DecoderStatus::Codes::kOk);
EXPECT_EQ(0, num_frames_in_decryptor_);
}
}
MOCK_METHOD1(FrameReady, void(scoped_refptr<AudioBuffer>));
- MOCK_METHOD1(DecodeDone, void(Status));
+ MOCK_METHOD1(DecodeDone, void(DecoderStatus));
MOCK_METHOD1(OnWaiting, void(WaitingReason));
scoped_refptr<DecoderBuffer> encrypted_buffer_;
scoped_refptr<AudioBuffer> decoded_frame_;
Decryptor::AudioFrames decoded_frame_list_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(DecryptingAudioDecoderTest);
};
TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) {
// Ensure decoder handles invalid audio configs without crashing.
TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) {
- AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat,
+ AudioDecoderConfig config(AudioCodec::kUnknown, kUnknownSampleFormat,
CHANNEL_LAYOUT_STEREO, 0, EmptyExtraData(),
EncryptionScheme::kCenc);
EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
.WillOnce(RunOnceCallback<1>(false));
- AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
+ AudioDecoderConfig config(AudioCodec::kVorbis, kSampleFormatPlanarF32,
CHANNEL_LAYOUT_STEREO, kSampleRate,
EmptyExtraData(), EncryptionScheme::kCenc);
InitializeAndExpectResult(config, false);
TEST_F(DecryptingAudioDecoderTest, Initialize_CdmWithoutDecryptor) {
SetCdmType(CDM_WITHOUT_DECRYPTOR);
- AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
+ AudioDecoderConfig config(AudioCodec::kVorbis, kSampleFormatPlanarF32,
CHANNEL_LAYOUT_STEREO, kSampleRate,
EmptyExtraData(), EncryptionScheme::kCenc);
InitializeAndExpectResult(config, false);
.WillRepeatedly(
RunOnceCallback<1>(Decryptor::kError, Decryptor::AudioFrames()));
- DecodeAndExpect(encrypted_buffer_, DecodeStatus::DECODE_ERROR);
+ DecodeAndExpect(encrypted_buffer_, DecoderStatus::Codes::kFailed);
}
// Test the case where the decryptor returns multiple decoded frames.
EXPECT_CALL(*this, FrameReady(decoded_frame_));
EXPECT_CALL(*this, FrameReady(frame_a));
EXPECT_CALL(*this, FrameReady(frame_b));
- DecodeAndExpect(encrypted_buffer_, DecodeStatus::OK);
+ DecodeAndExpect(encrypted_buffer_, DecoderStatus::Codes::kOk);
}
// Test the case where the decryptor receives end-of-stream buffer.
// The new config is different from the initial config in bits-per-channel,
// channel layout and samples_per_second.
- AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16,
+ AudioDecoderConfig new_config(AudioCodec::kVorbis, kSampleFormatPlanarS16,
CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(),
EncryptionScheme::kCenc);
EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
// The new config is different from the initial config in bits-per-channel,
// channel layout and samples_per_second.
- AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16,
+ AudioDecoderConfig new_config(AudioCodec::kVorbis, kSampleFormatPlanarS16,
CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(),
EncryptionScheme::kUnencrypted);
EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
Initialize();
EnterPendingDecodeState();
- EXPECT_CALL(*this, DecodeDone(HasStatusCode(StatusCode::kAborted)));
+ EXPECT_CALL(*this, DecodeDone(HasStatusCode(DecoderStatus::Codes::kAborted)));
Reset();
}
Initialize();
EnterWaitingForKeyState();
- EXPECT_CALL(*this, DecodeDone(HasStatusCode(StatusCode::kAborted)));
+ EXPECT_CALL(*this, DecodeDone(HasStatusCode(DecoderStatus::Codes::kAborted)));
Reset();
}