media: Allow config change between clear and encrypted streams
In the demuxer, we allow DecryptConfig change upon config change,
including but not limited to:
- switching between clear and encrypted
- encryption scheme change
Media Renderer implementation should support such changes. The detailed
requirement from the spec's perspective is tracked at:
https://github.com/w3c/encrypted-media/issues/251
Currently the default media Renderer (RendererImpl) supports switching
from encrypted to clear, because:
- Decrypt-and-decode mode: Decrypting{Audio|Video}Decoder supports clear
buffer.
- Decrypt-only mode: DecryptingDemuxerStream supports clear buffer.
However, switching from clear to encrypted is not supported in
RendererImpl, because the clear decoder doesn't support decryption. This
will be fixed in a later CL.
BUG=597443
TEST=Updated pipeline_integration_tests.
Review-Url: https://codereview.chromium.org/2543623003
Cr-Commit-Position: refs/heads/master@{#451212}
diff --git a/media/filters/decrypting_audio_decoder_unittest.cc b/media/filters/decrypting_audio_decoder_unittest.cc
index bd12003..830a5a11 100644
--- a/media/filters/decrypting_audio_decoder_unittest.cc
+++ b/media/filters/decrypting_audio_decoder_unittest.cc
@@ -281,15 +281,6 @@
Initialize();
}
-// Ensure that DecryptingAudioDecoder only accepts encrypted audio.
-TEST_F(DecryptingAudioDecoderTest, Initialize_UnencryptedAudioConfig) {
- AudioDecoderConfig config(kCodecVorbis, kSampleFormatPlanarF32,
- CHANNEL_LAYOUT_STEREO, kSampleRate,
- EmptyExtraData(), Unencrypted());
-
- InitializeAndExpectResult(config, false);
-}
-
// Ensure decoder handles invalid audio configs without crashing.
TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) {
AudioDecoderConfig config(kUnknownAudioCodec, kUnknownSampleFormat,
@@ -368,8 +359,8 @@
EnterEndOfStreamState();
}
-// Test reinitializing decode with a new config
-TEST_F(DecryptingAudioDecoderTest, Reinitialize_ConfigChange) {
+// Test reinitializing decode with a new encrypted config.
+TEST_F(DecryptingAudioDecoderTest, Reinitialize_EncryptedToEncrypted) {
Initialize();
EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
@@ -384,6 +375,29 @@
EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
EXPECT_NE(new_config.channel_layout(), config_.channel_layout());
EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second());
+ ASSERT_TRUE(new_config.is_encrypted());
+
+ ReinitializeConfigChange(new_config);
+ base::RunLoop().RunUntilIdle();
+}
+
+// Test reinitializing decode with a new clear config.
+TEST_F(DecryptingAudioDecoderTest, Reinitialize_EncryptedToClear) {
+ Initialize();
+
+ EXPECT_CALL(*decryptor_, InitializeAudioDecoder(_, _))
+ .Times(AtMost(1))
+ .WillOnce(RunCallback<1>(true));
+
+ // The new config is different from the initial config in bits-per-channel,
+ // channel layout and samples_per_second.
+ AudioDecoderConfig new_config(kCodecVorbis, kSampleFormatPlanarS16,
+ CHANNEL_LAYOUT_5_1, 88200, EmptyExtraData(),
+ Unencrypted());
+ EXPECT_NE(new_config.bits_per_channel(), config_.bits_per_channel());
+ EXPECT_NE(new_config.channel_layout(), config_.channel_layout());
+ EXPECT_NE(new_config.samples_per_second(), config_.samples_per_second());
+ ASSERT_FALSE(new_config.is_encrypted());
ReinitializeConfigChange(new_config);
base::RunLoop().RunUntilIdle();