xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | 1323b9c2 | 2015-12-23 06:22:36 | [diff] [blame] | 5 | #include <stdint.h> |
| 6 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "base/bind.h" |
| 11 | #include "base/callback_helpers.h" |
Lei Zhang | 079df01 | 2021-05-26 19:26:48 | [diff] [blame] | 12 | #include "base/cxx17_backports.h" |
fdoray | f920dcf | 2016-06-27 17:16:59 | [diff] [blame] | 13 | #include "base/run_loop.h" |
Marijn Kruisselbrink | 52a3524 | 2019-06-05 22:58:29 | [diff] [blame] | 14 | #include "base/test/gmock_callback_support.h" |
Daniel Cheng | 868ab27 | 2021-02-24 17:07:15 | [diff] [blame] | 15 | #include "base/test/gmock_move_support.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 16 | #include "base/test/task_environment.h" |
jrummell@chromium.org | 47b37a6 | 2013-07-10 03:56:10 | [diff] [blame] | 17 | #include "media/base/audio_buffer.h" |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 18 | #include "media/base/decoder_buffer.h" |
| 19 | #include "media/base/decrypt_config.h" |
chcunningham | 9812dd8 | 2015-10-20 01:42:09 | [diff] [blame] | 20 | #include "media/base/media_util.h" |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 21 | #include "media/base/mock_filters.h" |
scherkus@chromium.org | 1848da0 | 2012-12-06 06:58:38 | [diff] [blame] | 22 | #include "media/base/test_helpers.h" |
watk | 9f9dfdc9 | 2015-09-04 21:33:29 | [diff] [blame] | 23 | #include "media/base/timestamp_constants.h" |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 24 | #include "media/filters/decrypting_audio_decoder.h" |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 25 | #include "testing/gmock/include/gmock/gmock.h" |
| 26 | |
Jose Lopes | 109230ec | 2020-02-24 10:28:12 | [diff] [blame] | 27 | using ::base::test::RunOnceCallback; |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 28 | using ::testing::_; |
| 29 | using ::testing::AtMost; |
xhwang | 00f69db7 | 2015-11-12 07:32:37 | [diff] [blame] | 30 | using ::testing::Return; |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 31 | using ::testing::StrictMock; |
| 32 | |
| 33 | namespace media { |
| 34 | |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 35 | const int kSampleRate = 44100; |
rileya@chromium.org | 16ecd5f | 2014-03-20 05:41:07 | [diff] [blame] | 36 | |
xhwang@chromium.org | ecf1691 | 2013-01-12 16:55:22 | [diff] [blame] | 37 | // Make sure the kFakeAudioFrameSize is a valid frame size for all audio decoder |
| 38 | // configs used in this test. |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 39 | const int kFakeAudioFrameSize = 48; |
Avi Drissman | 97785ea | 2015-12-19 01:11:31 | [diff] [blame] | 40 | const uint8_t kFakeKeyId[] = {0x4b, 0x65, 0x79, 0x20, 0x49, 0x44}; |
| 41 | const uint8_t kFakeIv[DecryptConfig::kDecryptionKeySize] = {0}; |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 42 | const int kDecodingDelay = 3; |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 43 | |
| 44 | // Create a fake non-empty encrypted buffer. |
| 45 | static scoped_refptr<DecoderBuffer> CreateFakeEncryptedBuffer() { |
| 46 | const int buffer_size = 16; // Need a non-empty buffer; |
| 47 | scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(buffer_size)); |
John Rummell | 9044a76 | 2018-04-19 01:24:07 | [diff] [blame] | 48 | buffer->set_decrypt_config(DecryptConfig::CreateCencConfig( |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 49 | std::string(reinterpret_cast<const char*>(kFakeKeyId), |
Avi Drissman | fa9bed4 | 2018-12-25 20:26:39 | [diff] [blame] | 50 | base::size(kFakeKeyId)), |
| 51 | std::string(reinterpret_cast<const char*>(kFakeIv), base::size(kFakeIv)), |
John Rummell | 9044a76 | 2018-04-19 01:24:07 | [diff] [blame] | 52 | std::vector<SubsampleEntry>())); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 53 | return buffer; |
| 54 | } |
| 55 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 56 | class DecryptingAudioDecoderTest : public testing::Test { |
| 57 | public: |
| 58 | DecryptingAudioDecoderTest() |
Carlos Caballero | 9de7c72 | 2019-05-31 21:25:07 | [diff] [blame] | 59 | : decoder_(new DecryptingAudioDecoder( |
Gabriel Charette | dfa3604 | 2019-08-19 17:30:11 | [diff] [blame] | 60 | task_environment_.GetMainThreadTaskRunner(), |
Carlos Caballero | 9de7c72 | 2019-05-31 21:25:07 | [diff] [blame] | 61 | &media_log_)), |
xhwang | 00f69db7 | 2015-11-12 07:32:37 | [diff] [blame] | 62 | cdm_context_(new StrictMock<MockCdmContext>()), |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 63 | decryptor_(new StrictMock<MockDecryptor>()), |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 64 | num_decrypt_and_decode_calls_(0), |
| 65 | num_frames_in_decryptor_(0), |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 66 | encrypted_buffer_(CreateFakeEncryptedBuffer()), |
kylechar | 938dc44 | 2019-10-29 14:40:24 | [diff] [blame] | 67 | decoded_frame_(nullptr), |
rileya@chromium.org | d7015779 | 2014-03-17 21:45:03 | [diff] [blame] | 68 | decoded_frame_list_() {} |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 69 | |
Peter Boström | 4c42559f | 2021-09-22 20:24:34 | [diff] [blame] | 70 | DecryptingAudioDecoderTest(const DecryptingAudioDecoderTest&) = delete; |
| 71 | DecryptingAudioDecoderTest& operator=(const DecryptingAudioDecoderTest&) = |
| 72 | delete; |
| 73 | |
Daniel Cheng | 9f0b701 | 2018-04-26 21:09:05 | [diff] [blame] | 74 | ~DecryptingAudioDecoderTest() override { Destroy(); } |
rileya@chromium.org | b960fd0 | 2014-01-23 04:48:54 | [diff] [blame] | 75 | |
xhwang | 59c321f | 2015-06-05 23:46:55 | [diff] [blame] | 76 | void InitializeAndExpectResult(const AudioDecoderConfig& config, |
| 77 | bool success) { |
dalecurtis@google.com | e81f5f9d | 2014-03-29 01:32:16 | [diff] [blame] | 78 | // Initialize data now that the config is known. Since the code uses |
| 79 | // invalid values (that CreateEmptyBuffer() doesn't support), tweak them |
| 80 | // just for CreateEmptyBuffer(). |
| 81 | int channels = ChannelLayoutToChannelCount(config.channel_layout()); |
| 82 | if (channels < 0) |
| 83 | channels = 0; |
dalecurtis | 39a7f93 | 2016-07-19 18:34:59 | [diff] [blame] | 84 | decoded_frame_ = AudioBuffer::CreateEmptyBuffer( |
| 85 | config.channel_layout(), channels, kSampleRate, kFakeAudioFrameSize, |
| 86 | kNoTimestamp); |
jrummell@chromium.org | 47b37a6 | 2013-07-10 03:56:10 | [diff] [blame] | 87 | decoded_frame_list_.push_back(decoded_frame_); |
| 88 | |
David Bienvenu | b8c8752 | 2020-11-11 22:59:50 | [diff] [blame] | 89 | decoder_->Initialize( |
| 90 | config, cdm_context_.get(), |
| 91 | base::BindOnce( |
Ted Meyer | a8afec22 | 2022-01-12 02:37:27 | [diff] [blame^] | 92 | [](bool success, DecoderStatus status) { |
David Bienvenu | b8c8752 | 2020-11-11 22:59:50 | [diff] [blame] | 93 | EXPECT_EQ(status.is_ok(), success); |
| 94 | }, |
| 95 | success), |
| 96 | base::BindRepeating(&DecryptingAudioDecoderTest::FrameReady, |
| 97 | base::Unretained(this)), |
| 98 | base::BindRepeating(&DecryptingAudioDecoderTest::OnWaiting, |
| 99 | base::Unretained(this))); |
fdoray | f920dcf | 2016-06-27 17:16:59 | [diff] [blame] | 100 | base::RunLoop().RunUntilIdle(); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 101 | } |
| 102 | |
xhwang | a935e44 | 2016-02-11 02:22:45 | [diff] [blame] | 103 | enum CdmType { CDM_WITHOUT_DECRYPTOR, CDM_WITH_DECRYPTOR }; |
xhwang | 00f69db7 | 2015-11-12 07:32:37 | [diff] [blame] | 104 | |
| 105 | void SetCdmType(CdmType cdm_type) { |
xhwang | 00f69db7 | 2015-11-12 07:32:37 | [diff] [blame] | 106 | const bool has_decryptor = cdm_type == CDM_WITH_DECRYPTOR; |
xhwang | a935e44 | 2016-02-11 02:22:45 | [diff] [blame] | 107 | EXPECT_CALL(*cdm_context_, GetDecryptor()) |
| 108 | .WillRepeatedly(Return(has_decryptor ? decryptor_.get() : nullptr)); |
jrummell@chromium.org | 9ebc3b03 | 2014-08-13 04:01:23 | [diff] [blame] | 109 | } |
| 110 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 111 | void Initialize() { |
xhwang | 00f69db7 | 2015-11-12 07:32:37 | [diff] [blame] | 112 | SetCdmType(CDM_WITH_DECRYPTOR); |
xhwang@chromium.org | a3e2867 | 2013-03-14 14:54:59 | [diff] [blame] | 113 | EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 114 | .Times(AtMost(1)) |
Jose Lopes | 109230ec | 2020-02-24 10:28:12 | [diff] [blame] | 115 | .WillOnce(RunOnceCallback<1>(true)); |
Xiaohan Wang | d72ce5d | 2020-07-14 01:34:43 | [diff] [blame] | 116 | EXPECT_CALL(*cdm_context_, RegisterEventCB(_)).WillOnce([&](auto cb) { |
| 117 | event_cb_ = cb; |
| 118 | return std::make_unique<CallbackRegistration>(); |
| 119 | }); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 120 | |
Dale Curtis | bafd56317 | 2021-08-13 02:07:47 | [diff] [blame] | 121 | config_.Initialize(AudioCodec::kVorbis, kSampleFormatPlanarF32, |
chcunningham | 9812dd8 | 2015-10-20 01:42:09 | [diff] [blame] | 122 | CHANNEL_LAYOUT_STEREO, kSampleRate, EmptyExtraData(), |
Yuchen Liu | b33bfc1 | 2019-11-08 20:16:12 | [diff] [blame] | 123 | EncryptionScheme::kCenc, base::TimeDelta(), 0); |
xhwang | 59c321f | 2015-06-05 23:46:55 | [diff] [blame] | 124 | InitializeAndExpectResult(config_, true); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 125 | } |
| 126 | |
Xiaohan Wang | c03ce23 | 2018-05-30 21:07:58 | [diff] [blame] | 127 | void Reinitialize() { ReinitializeConfigChange(config_); } |
rileya@chromium.org | d7015779 | 2014-03-17 21:45:03 | [diff] [blame] | 128 | |
dalecurtis@google.com | 6fb8654 | 2014-04-18 19:58:13 | [diff] [blame] | 129 | void ReinitializeConfigChange(const AudioDecoderConfig& new_config) { |
rileya@chromium.org | d7015779 | 2014-03-17 21:45:03 | [diff] [blame] | 130 | EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)); |
| 131 | EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
Jose Lopes | 109230ec | 2020-02-24 10:28:12 | [diff] [blame] | 132 | .WillOnce(RunOnceCallback<1>(true)); |
Ted Meyer | 2a41e24 | 2020-03-20 08:01:27 | [diff] [blame] | 133 | decoder_->Initialize( |
| 134 | new_config, cdm_context_.get(), |
Ted Meyer | a8afec22 | 2022-01-12 02:37:27 | [diff] [blame^] | 135 | base::BindOnce( |
| 136 | [](DecoderStatus status) { EXPECT_TRUE(status.is_ok()); }), |
David Bienvenu | b8c8752 | 2020-11-11 22:59:50 | [diff] [blame] | 137 | base::BindRepeating(&DecryptingAudioDecoderTest::FrameReady, |
| 138 | base::Unretained(this)), |
| 139 | base::BindRepeating(&DecryptingAudioDecoderTest::OnWaiting, |
| 140 | base::Unretained(this))); |
rileya@chromium.org | d7015779 | 2014-03-17 21:45:03 | [diff] [blame] | 141 | } |
| 142 | |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 143 | // Decode |buffer| and expect DecodeDone to get called with |status|. |
Ted Meyer | a8afec22 | 2022-01-12 02:37:27 | [diff] [blame^] | 144 | void DecodeAndExpect(scoped_refptr<DecoderBuffer> buffer, |
| 145 | DecoderStatus status) { |
Frank Liberato | 3d157ba | 2020-09-24 18:19:30 | [diff] [blame] | 146 | EXPECT_CALL(*this, DecodeDone(HasStatusCode(status))); |
David Bienvenu | b8c8752 | 2020-11-11 22:59:50 | [diff] [blame] | 147 | decoder_->Decode(buffer, |
| 148 | base::BindOnce(&DecryptingAudioDecoderTest::DecodeDone, |
| 149 | base::Unretained(this))); |
fdoray | f920dcf | 2016-06-27 17:16:59 | [diff] [blame] | 150 | base::RunLoop().RunUntilIdle(); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 151 | } |
| 152 | |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 153 | // Helper function to simulate the decrypting and decoding process in the |
| 154 | // |decryptor_| with a decoding delay of kDecodingDelay buffers. |
Dale Curtis | ca8ad98 | 2018-04-09 20:23:14 | [diff] [blame] | 155 | void DecryptAndDecodeAudio(scoped_refptr<DecoderBuffer> encrypted, |
Daniel Cheng | 868ab27 | 2021-02-24 17:07:15 | [diff] [blame] | 156 | Decryptor::AudioDecodeCB audio_decode_cb) { |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 157 | num_decrypt_and_decode_calls_++; |
| 158 | if (!encrypted->end_of_stream()) |
| 159 | num_frames_in_decryptor_++; |
| 160 | |
| 161 | if (num_decrypt_and_decode_calls_ <= kDecodingDelay || |
| 162 | num_frames_in_decryptor_ == 0) { |
Daniel Cheng | 868ab27 | 2021-02-24 17:07:15 | [diff] [blame] | 163 | std::move(audio_decode_cb) |
| 164 | .Run(Decryptor::kNeedMoreData, Decryptor::AudioFrames()); |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 165 | return; |
| 166 | } |
| 167 | |
| 168 | num_frames_in_decryptor_--; |
Daniel Cheng | 868ab27 | 2021-02-24 17:07:15 | [diff] [blame] | 169 | std::move(audio_decode_cb) |
| 170 | .Run(Decryptor::kSuccess, Decryptor::AudioFrames(1, decoded_frame_)); |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 171 | } |
| 172 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 173 | // Sets up expectations and actions to put DecryptingAudioDecoder in an |
| 174 | // active normal decoding state. |
| 175 | void EnterNormalDecodingState() { |
Xiaohan Wang | c03ce23 | 2018-05-30 21:07:58 | [diff] [blame] | 176 | EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
| 177 | .WillRepeatedly( |
| 178 | Invoke(this, &DecryptingAudioDecoderTest::DecryptAndDecodeAudio)); |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 179 | EXPECT_CALL(*this, FrameReady(decoded_frame_)); |
| 180 | for (int i = 0; i < kDecodingDelay + 1; ++i) |
Ted Meyer | a8afec22 | 2022-01-12 02:37:27 | [diff] [blame^] | 181 | DecodeAndExpect(encrypted_buffer_, DecoderStatus::Codes::kOk); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // Sets up expectations and actions to put DecryptingAudioDecoder in an end |
| 185 | // of stream state. This function must be called after |
| 186 | // EnterNormalDecodingState() to work. |
| 187 | void EnterEndOfStreamState() { |
xhwang@chromium.org | ff75703 | 2014-06-19 01:42:24 | [diff] [blame] | 188 | // The codec in the |decryptor_| will be flushed. |
Xiaohan Wang | c03ce23 | 2018-05-30 21:07:58 | [diff] [blame] | 189 | EXPECT_CALL(*this, FrameReady(decoded_frame_)).Times(kDecodingDelay); |
Ted Meyer | a8afec22 | 2022-01-12 02:37:27 | [diff] [blame^] | 190 | DecodeAndExpect(DecoderBuffer::CreateEOSBuffer(), |
| 191 | DecoderStatus::Codes::kOk); |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 192 | EXPECT_EQ(0, num_frames_in_decryptor_); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | // Make the audio decode callback pending by saving and not firing it. |
| 196 | void EnterPendingDecodeState() { |
Dale Curtis | e2516381 | 2018-09-21 22:13:39 | [diff] [blame] | 197 | EXPECT_TRUE(!pending_audio_decode_cb_); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 198 | EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _)) |
Daniel Cheng | 868ab27 | 2021-02-24 17:07:15 | [diff] [blame] | 199 | .WillOnce(MoveArg<1>(&pending_audio_decode_cb_)); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 200 | |
rileya@chromium.org | d7015779 | 2014-03-17 21:45:03 | [diff] [blame] | 201 | decoder_->Decode(encrypted_buffer_, |
David Bienvenu | b8c8752 | 2020-11-11 22:59:50 | [diff] [blame] | 202 | base::BindOnce(&DecryptingAudioDecoderTest::DecodeDone, |
| 203 | base::Unretained(this))); |
fdoray | f920dcf | 2016-06-27 17:16:59 | [diff] [blame] | 204 | base::RunLoop().RunUntilIdle(); |
rileya@chromium.org | d7015779 | 2014-03-17 21:45:03 | [diff] [blame] | 205 | // Make sure the Decode() on the decoder triggers a DecryptAndDecode() on |
| 206 | // the decryptor. |
Dale Curtis | e2516381 | 2018-09-21 22:13:39 | [diff] [blame] | 207 | EXPECT_FALSE(!pending_audio_decode_cb_); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | void EnterWaitingForKeyState() { |
xhwang@chromium.org | 2b454ff8 | 2012-11-15 03:57:58 | [diff] [blame] | 211 | EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(encrypted_buffer_, _)) |
Xiaohan Wang | c03ce23 | 2018-05-30 21:07:58 | [diff] [blame] | 212 | .WillRepeatedly( |
Daniel Cheng | 868ab27 | 2021-02-24 17:07:15 | [diff] [blame] | 213 | RunOnceCallback<1>(Decryptor::kNoKey, Decryptor::AudioFrames())); |
Xiaohan Wang | 640b41d | 2018-12-18 19:00:46 | [diff] [blame] | 214 | EXPECT_CALL(*this, OnWaiting(WaitingReason::kNoDecryptionKey)); |
rileya@chromium.org | d7015779 | 2014-03-17 21:45:03 | [diff] [blame] | 215 | decoder_->Decode(encrypted_buffer_, |
David Bienvenu | b8c8752 | 2020-11-11 22:59:50 | [diff] [blame] | 216 | base::BindOnce(&DecryptingAudioDecoderTest::DecodeDone, |
| 217 | base::Unretained(this))); |
Xiaohan Wang | 689cd428 | 2017-08-04 07:54:55 | [diff] [blame] | 218 | |
fdoray | f920dcf | 2016-06-27 17:16:59 | [diff] [blame] | 219 | base::RunLoop().RunUntilIdle(); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void AbortPendingAudioDecodeCB() { |
Dale Curtis | e2516381 | 2018-09-21 22:13:39 | [diff] [blame] | 223 | if (pending_audio_decode_cb_) { |
| 224 | std::move(pending_audio_decode_cb_) |
Xiaohan Wang | c03ce23 | 2018-05-30 21:07:58 | [diff] [blame] | 225 | .Run(Decryptor::kSuccess, Decryptor::AudioFrames()); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
rileya@chromium.org | b960fd0 | 2014-01-23 04:48:54 | [diff] [blame] | 229 | void AbortAllPendingCBs() { |
Dale Curtis | e2516381 | 2018-09-21 22:13:39 | [diff] [blame] | 230 | if (pending_init_cb_) { |
| 231 | ASSERT_TRUE(!pending_audio_decode_cb_); |
| 232 | std::move(pending_init_cb_).Run(false); |
rileya@chromium.org | b960fd0 | 2014-01-23 04:48:54 | [diff] [blame] | 233 | return; |
| 234 | } |
| 235 | |
| 236 | AbortPendingAudioDecodeCB(); |
| 237 | } |
| 238 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 239 | void Reset() { |
| 240 | EXPECT_CALL(*decryptor_, ResetDecoder(Decryptor::kAudio)) |
| 241 | .WillRepeatedly(InvokeWithoutArgs( |
| 242 | this, &DecryptingAudioDecoderTest::AbortPendingAudioDecodeCB)); |
| 243 | |
| 244 | decoder_->Reset(NewExpectedClosure()); |
fdoray | f920dcf | 2016-06-27 17:16:59 | [diff] [blame] | 245 | base::RunLoop().RunUntilIdle(); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 246 | } |
| 247 | |
xhwang@chromium.org | 83fb2a9e | 2014-07-16 23:36:41 | [diff] [blame] | 248 | void Destroy() { |
rileya@chromium.org | b960fd0 | 2014-01-23 04:48:54 | [diff] [blame] | 249 | EXPECT_CALL(*decryptor_, DeinitializeDecoder(Decryptor::kAudio)) |
| 250 | .WillRepeatedly(InvokeWithoutArgs( |
| 251 | this, &DecryptingAudioDecoderTest::AbortAllPendingCBs)); |
| 252 | |
xhwang@chromium.org | 83fb2a9e | 2014-07-16 23:36:41 | [diff] [blame] | 253 | decoder_.reset(); |
fdoray | f920dcf | 2016-06-27 17:16:59 | [diff] [blame] | 254 | base::RunLoop().RunUntilIdle(); |
rileya@chromium.org | b960fd0 | 2014-01-23 04:48:54 | [diff] [blame] | 255 | } |
| 256 | |
John Rummell | 1b2b63d | 2019-04-26 20:45:57 | [diff] [blame] | 257 | MOCK_METHOD1(FrameReady, void(scoped_refptr<AudioBuffer>)); |
Ted Meyer | a8afec22 | 2022-01-12 02:37:27 | [diff] [blame^] | 258 | MOCK_METHOD1(DecodeDone, void(DecoderStatus)); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 259 | |
Xiaohan Wang | 640b41d | 2018-12-18 19:00:46 | [diff] [blame] | 260 | MOCK_METHOD1(OnWaiting, void(WaitingReason)); |
jrummell | 74fc4f94 | 2015-03-02 22:48:27 | [diff] [blame] | 261 | |
Gabriel Charette | 311b0e9 | 2019-09-09 20:01:25 | [diff] [blame] | 262 | base::test::SingleThreadTaskEnvironment task_environment_; |
Xiaohan Wang | 14b3166d | 2018-12-28 21:05:46 | [diff] [blame] | 263 | NullMediaLog media_log_; |
dcheng | 254c536 | 2016-04-22 01:12:48 | [diff] [blame] | 264 | std::unique_ptr<DecryptingAudioDecoder> decoder_; |
| 265 | std::unique_ptr<StrictMock<MockCdmContext>> cdm_context_; |
| 266 | std::unique_ptr<StrictMock<MockDecryptor>> decryptor_; |
xhwang@chromium.org | 7c39486c | 2013-01-06 15:36:09 | [diff] [blame] | 267 | AudioDecoderConfig config_; |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 268 | |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 269 | // Variables to help the |decryptor_| to simulate decoding delay and flushing. |
| 270 | int num_decrypt_and_decode_calls_; |
| 271 | int num_frames_in_decryptor_; |
| 272 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 273 | Decryptor::DecoderInitCB pending_init_cb_; |
Xiaohan Wang | d72ce5d | 2020-07-14 01:34:43 | [diff] [blame] | 274 | CdmContext::EventCB event_cb_; |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 275 | Decryptor::AudioDecodeCB pending_audio_decode_cb_; |
| 276 | |
rileya@chromium.org | d7015779 | 2014-03-17 21:45:03 | [diff] [blame] | 277 | // Constant buffer/frames, to be used/returned by |decoder_| and |decryptor_|. |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 278 | scoped_refptr<DecoderBuffer> encrypted_buffer_; |
jrummell@chromium.org | 47b37a6 | 2013-07-10 03:56:10 | [diff] [blame] | 279 | scoped_refptr<AudioBuffer> decoded_frame_; |
anujk.sharma | f1cb600a | 2015-01-07 19:11:13 | [diff] [blame] | 280 | Decryptor::AudioFrames decoded_frame_list_; |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | TEST_F(DecryptingAudioDecoderTest, Initialize_Normal) { |
| 284 | Initialize(); |
| 285 | } |
| 286 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 287 | // Ensure decoder handles invalid audio configs without crashing. |
| 288 | TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) { |
Dale Curtis | bafd56317 | 2021-08-13 02:07:47 | [diff] [blame] | 289 | AudioDecoderConfig config(AudioCodec::kUnknown, kUnknownSampleFormat, |
dougsteed | 8d5275f | 2016-03-12 00:04:30 | [diff] [blame] | 290 | CHANNEL_LAYOUT_STEREO, 0, EmptyExtraData(), |
Yuchen Liu | b33bfc1 | 2019-11-08 20:16:12 | [diff] [blame] | 291 | EncryptionScheme::kCenc); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 292 | |
xhwang | 59c321f | 2015-06-05 23:46:55 | [diff] [blame] | 293 | InitializeAndExpectResult(config, false); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | // Ensure decoder handles unsupported audio configs without crashing. |
| 297 | TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { |
xhwang | 00f69db7 | 2015-11-12 07:32:37 | [diff] [blame] | 298 | SetCdmType(CDM_WITH_DECRYPTOR); |
Xiaohan Wang | d72ce5d | 2020-07-14 01:34:43 | [diff] [blame] | 299 | EXPECT_CALL(*cdm_context_, RegisterEventCB(_)).WillOnce([&](auto cb) { |
| 300 | event_cb_ = cb; |
| 301 | return std::make_unique<CallbackRegistration>(); |
| 302 | }); |
xhwang@chromium.org | a3e2867 | 2013-03-14 14:54:59 | [diff] [blame] | 303 | EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
Jose Lopes | 109230ec | 2020-02-24 10:28:12 | [diff] [blame] | 304 | .WillOnce(RunOnceCallback<1>(false)); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 305 | |
Dale Curtis | bafd56317 | 2021-08-13 02:07:47 | [diff] [blame] | 306 | AudioDecoderConfig config(AudioCodec::kVorbis, kSampleFormatPlanarF32, |
chcunningham | 9812dd8 | 2015-10-20 01:42:09 | [diff] [blame] | 307 | CHANNEL_LAYOUT_STEREO, kSampleRate, |
Yuchen Liu | b33bfc1 | 2019-11-08 20:16:12 | [diff] [blame] | 308 | EmptyExtraData(), EncryptionScheme::kCenc); |
xhwang | 59c321f | 2015-06-05 23:46:55 | [diff] [blame] | 309 | InitializeAndExpectResult(config, false); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 310 | } |
| 311 | |
xhwang | 00f69db7 | 2015-11-12 07:32:37 | [diff] [blame] | 312 | TEST_F(DecryptingAudioDecoderTest, Initialize_CdmWithoutDecryptor) { |
| 313 | SetCdmType(CDM_WITHOUT_DECRYPTOR); |
Dale Curtis | bafd56317 | 2021-08-13 02:07:47 | [diff] [blame] | 314 | AudioDecoderConfig config(AudioCodec::kVorbis, kSampleFormatPlanarF32, |
chcunningham | 9812dd8 | 2015-10-20 01:42:09 | [diff] [blame] | 315 | CHANNEL_LAYOUT_STEREO, kSampleRate, |
Yuchen Liu | b33bfc1 | 2019-11-08 20:16:12 | [diff] [blame] | 316 | EmptyExtraData(), EncryptionScheme::kCenc); |
xhwang | 59c321f | 2015-06-05 23:46:55 | [diff] [blame] | 317 | InitializeAndExpectResult(config, false); |
xhwang@chromium.org | 699b64a | 2013-06-19 07:36:05 | [diff] [blame] | 318 | } |
| 319 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 320 | // Test normal decrypt and decode case. |
| 321 | TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_Normal) { |
| 322 | Initialize(); |
| 323 | EnterNormalDecodingState(); |
| 324 | } |
| 325 | |
| 326 | // Test the case where the decryptor returns error when doing decrypt and |
| 327 | // decode. |
| 328 | TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_DecodeError) { |
| 329 | Initialize(); |
| 330 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 331 | EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
Xiaohan Wang | c03ce23 | 2018-05-30 21:07:58 | [diff] [blame] | 332 | .WillRepeatedly( |
Daniel Cheng | 868ab27 | 2021-02-24 17:07:15 | [diff] [blame] | 333 | RunOnceCallback<1>(Decryptor::kError, Decryptor::AudioFrames())); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 334 | |
Ted Meyer | a8afec22 | 2022-01-12 02:37:27 | [diff] [blame^] | 335 | DecodeAndExpect(encrypted_buffer_, DecoderStatus::Codes::kFailed); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | // Test the case where the decryptor returns multiple decoded frames. |
| 339 | TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) { |
| 340 | Initialize(); |
| 341 | |
jrummell@chromium.org | 47b37a6 | 2013-07-10 03:56:10 | [diff] [blame] | 342 | scoped_refptr<AudioBuffer> frame_a = AudioBuffer::CreateEmptyBuffer( |
rileya@chromium.org | 16ecd5f | 2014-03-20 05:41:07 | [diff] [blame] | 343 | config_.channel_layout(), |
dalecurtis | 39a7f93 | 2016-07-19 18:34:59 | [diff] [blame] | 344 | ChannelLayoutToChannelCount(config_.channel_layout()), kSampleRate, |
| 345 | kFakeAudioFrameSize, kNoTimestamp); |
jrummell@chromium.org | 47b37a6 | 2013-07-10 03:56:10 | [diff] [blame] | 346 | scoped_refptr<AudioBuffer> frame_b = AudioBuffer::CreateEmptyBuffer( |
rileya@chromium.org | 16ecd5f | 2014-03-20 05:41:07 | [diff] [blame] | 347 | config_.channel_layout(), |
dalecurtis | 39a7f93 | 2016-07-19 18:34:59 | [diff] [blame] | 348 | ChannelLayoutToChannelCount(config_.channel_layout()), kSampleRate, |
| 349 | kFakeAudioFrameSize, kNoTimestamp); |
xhwang@chromium.org | ecbb976 | 2012-10-24 22:33:54 | [diff] [blame] | 350 | decoded_frame_list_.push_back(frame_a); |
| 351 | decoded_frame_list_.push_back(frame_b); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 352 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 353 | EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
Daniel Cheng | 868ab27 | 2021-02-24 17:07:15 | [diff] [blame] | 354 | .WillOnce(RunOnceCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 355 | |
xhwang@chromium.org | 5c5e9b7 | 2014-06-17 19:21:12 | [diff] [blame] | 356 | EXPECT_CALL(*this, FrameReady(decoded_frame_)); |
| 357 | EXPECT_CALL(*this, FrameReady(frame_a)); |
| 358 | EXPECT_CALL(*this, FrameReady(frame_b)); |
Ted Meyer | a8afec22 | 2022-01-12 02:37:27 | [diff] [blame^] | 359 | DecodeAndExpect(encrypted_buffer_, DecoderStatus::Codes::kOk); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | // Test the case where the decryptor receives end-of-stream buffer. |
| 363 | TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_EndOfStream) { |
| 364 | Initialize(); |
| 365 | EnterNormalDecodingState(); |
| 366 | EnterEndOfStreamState(); |
| 367 | } |
| 368 | |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 369 | // Test reinitializing decode with a new encrypted config. |
| 370 | TEST_F(DecryptingAudioDecoderTest, Reinitialize_EncryptedToEncrypted) { |
xhwang@chromium.org | 7c39486c | 2013-01-06 15:36:09 | [diff] [blame] | 371 | Initialize(); |
| 372 | |
rileya@chromium.org | d7015779 | 2014-03-17 21:45:03 | [diff] [blame] | 373 | EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| 374 | .Times(AtMost(1)) |
Jose Lopes | 109230ec | 2020-02-24 10:28:12 | [diff] [blame] | 375 | .WillOnce(RunOnceCallback<1>(true)); |
xhwang@chromium.org | 7c39486c | 2013-01-06 15:36:09 | [diff] [blame] | 376 | |
xhwang@chromium.org | ecf1691 | 2013-01-12 16:55:22 | [diff] [blame] | 377 | // The new config is different from the initial config in bits-per-channel, |
| 378 | // channel layout and samples_per_second. |
Dale Curtis | bafd56317 | 2021-08-13 02:07:47 | [diff] [blame] | 379 | AudioDecoderConfig new_config(AudioCodec::kVorbis, kSampleFormatPlanarS16, |
chcunningham | 9812dd8 | 2015-10-20 01:42:09 | [diff] [blame] | 380 | CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(), |
Yuchen Liu | b33bfc1 | 2019-11-08 20:16:12 | [diff] [blame] | 381 | EncryptionScheme::kCenc); |
xhwang@chromium.org | ecf1691 | 2013-01-12 16:55:22 | [diff] [blame] | 382 | EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel()); |
| 383 | EXPECT_NE(new_config.channel_layout(), config_.channel_layout()); |
| 384 | EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second()); |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 385 | ASSERT_TRUE(new_config.is_encrypted()); |
| 386 | |
| 387 | ReinitializeConfigChange(new_config); |
| 388 | base::RunLoop().RunUntilIdle(); |
| 389 | } |
| 390 | |
| 391 | // Test reinitializing decode with a new clear config. |
| 392 | TEST_F(DecryptingAudioDecoderTest, Reinitialize_EncryptedToClear) { |
| 393 | Initialize(); |
| 394 | |
| 395 | EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _)) |
| 396 | .Times(AtMost(1)) |
Jose Lopes | 109230ec | 2020-02-24 10:28:12 | [diff] [blame] | 397 | .WillOnce(RunOnceCallback<1>(true)); |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 398 | |
| 399 | // The new config is different from the initial config in bits-per-channel, |
| 400 | // channel layout and samples_per_second. |
Dale Curtis | bafd56317 | 2021-08-13 02:07:47 | [diff] [blame] | 401 | AudioDecoderConfig new_config(AudioCodec::kVorbis, kSampleFormatPlanarS16, |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 402 | CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(), |
Yuchen Liu | b33bfc1 | 2019-11-08 20:16:12 | [diff] [blame] | 403 | EncryptionScheme::kUnencrypted); |
xhwang | 65c2303 | 2017-02-17 04:37:42 | [diff] [blame] | 404 | EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel()); |
| 405 | EXPECT_NE(new_config.channel_layout(), config_.channel_layout()); |
| 406 | EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second()); |
| 407 | ASSERT_FALSE(new_config.is_encrypted()); |
xhwang@chromium.org | ecf1691 | 2013-01-12 16:55:22 | [diff] [blame] | 408 | |
rileya@chromium.org | d7015779 | 2014-03-17 21:45:03 | [diff] [blame] | 409 | ReinitializeConfigChange(new_config); |
fdoray | f920dcf | 2016-06-27 17:16:59 | [diff] [blame] | 410 | base::RunLoop().RunUntilIdle(); |
xhwang@chromium.org | 7c39486c | 2013-01-06 15:36:09 | [diff] [blame] | 411 | } |
| 412 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 413 | // Test the case where the a key is added when the decryptor is in |
| 414 | // kWaitingForKey state. |
| 415 | TEST_F(DecryptingAudioDecoderTest, KeyAdded_DuringWaitingForKey) { |
| 416 | Initialize(); |
| 417 | EnterWaitingForKeyState(); |
| 418 | |
| 419 | EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
Daniel Cheng | 868ab27 | 2021-02-24 17:07:15 | [diff] [blame] | 420 | .WillRepeatedly( |
| 421 | RunOnceCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); |
sergeyu@chromium.org | 49cea86 | 2014-06-11 11:11:50 | [diff] [blame] | 422 | EXPECT_CALL(*this, FrameReady(decoded_frame_)); |
Frank Liberato | 3d157ba | 2020-09-24 18:19:30 | [diff] [blame] | 423 | EXPECT_CALL(*this, DecodeDone(IsOkStatus())); |
Xiaohan Wang | d72ce5d | 2020-07-14 01:34:43 | [diff] [blame] | 424 | event_cb_.Run(CdmContext::Event::kHasAdditionalUsableKey); |
fdoray | f920dcf | 2016-06-27 17:16:59 | [diff] [blame] | 425 | base::RunLoop().RunUntilIdle(); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | // Test the case where the a key is added when the decryptor is in |
| 429 | // kPendingDecode state. |
| 430 | TEST_F(DecryptingAudioDecoderTest, KeyAdded_DruingPendingDecode) { |
| 431 | Initialize(); |
| 432 | EnterPendingDecodeState(); |
| 433 | |
| 434 | EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) |
Daniel Cheng | 868ab27 | 2021-02-24 17:07:15 | [diff] [blame] | 435 | .WillRepeatedly( |
| 436 | RunOnceCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); |
sergeyu@chromium.org | 49cea86 | 2014-06-11 11:11:50 | [diff] [blame] | 437 | EXPECT_CALL(*this, FrameReady(decoded_frame_)); |
Frank Liberato | 3d157ba | 2020-09-24 18:19:30 | [diff] [blame] | 438 | EXPECT_CALL(*this, DecodeDone(IsOkStatus())); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 439 | // The audio decode callback is returned after the correct decryption key is |
| 440 | // added. |
Xiaohan Wang | d72ce5d | 2020-07-14 01:34:43 | [diff] [blame] | 441 | event_cb_.Run(CdmContext::Event::kHasAdditionalUsableKey); |
Dale Curtis | e2516381 | 2018-09-21 22:13:39 | [diff] [blame] | 442 | std::move(pending_audio_decode_cb_) |
Xiaohan Wang | c03ce23 | 2018-05-30 21:07:58 | [diff] [blame] | 443 | .Run(Decryptor::kNoKey, Decryptor::AudioFrames()); |
fdoray | f920dcf | 2016-06-27 17:16:59 | [diff] [blame] | 444 | base::RunLoop().RunUntilIdle(); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | // Test resetting when the decoder is in kIdle state but has not decoded any |
| 448 | // frame. |
| 449 | TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterInitialization) { |
| 450 | Initialize(); |
| 451 | Reset(); |
| 452 | } |
| 453 | |
| 454 | // Test resetting when the decoder is in kIdle state after it has decoded one |
| 455 | // frame. |
| 456 | TEST_F(DecryptingAudioDecoderTest, Reset_DuringIdleAfterDecodedOneFrame) { |
| 457 | Initialize(); |
| 458 | EnterNormalDecodingState(); |
| 459 | Reset(); |
| 460 | } |
| 461 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 462 | // Test resetting when the decoder is in kPendingDecode state. |
| 463 | TEST_F(DecryptingAudioDecoderTest, Reset_DuringPendingDecode) { |
| 464 | Initialize(); |
| 465 | EnterPendingDecodeState(); |
| 466 | |
Ted Meyer | a8afec22 | 2022-01-12 02:37:27 | [diff] [blame^] | 467 | EXPECT_CALL(*this, DecodeDone(HasStatusCode(DecoderStatus::Codes::kAborted))); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 468 | |
| 469 | Reset(); |
| 470 | } |
| 471 | |
| 472 | // Test resetting when the decoder is in kWaitingForKey state. |
| 473 | TEST_F(DecryptingAudioDecoderTest, Reset_DuringWaitingForKey) { |
| 474 | Initialize(); |
| 475 | EnterWaitingForKeyState(); |
| 476 | |
Ted Meyer | a8afec22 | 2022-01-12 02:37:27 | [diff] [blame^] | 477 | EXPECT_CALL(*this, DecodeDone(HasStatusCode(DecoderStatus::Codes::kAborted))); |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 478 | |
| 479 | Reset(); |
| 480 | } |
| 481 | |
| 482 | // Test resetting when the decoder has hit end of stream and is in |
| 483 | // kDecodeFinished state. |
| 484 | TEST_F(DecryptingAudioDecoderTest, Reset_AfterDecodeFinished) { |
| 485 | Initialize(); |
| 486 | EnterNormalDecodingState(); |
| 487 | EnterEndOfStreamState(); |
| 488 | Reset(); |
| 489 | } |
| 490 | |
| 491 | // Test resetting after the decoder has been reset. |
| 492 | TEST_F(DecryptingAudioDecoderTest, Reset_AfterReset) { |
| 493 | Initialize(); |
| 494 | EnterNormalDecodingState(); |
| 495 | Reset(); |
| 496 | Reset(); |
| 497 | } |
| 498 | |
xhwang@chromium.org | 97a9ce4 | 2012-10-19 10:06:43 | [diff] [blame] | 499 | } // namespace media |