1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/mojo/mojom/audio_decoder_config_mojom_traits.h"
9 #include "media/base/audio_decoder_config.h"
10 #include "media/base/media_util.h"
11 #include "mojo/public/cpp/base/time_mojom_traits.h"
12 #include "testing/gtest/include/gtest/gtest.h"
16 TEST(AudioDecoderConfigStructTraitsTest, Normal) {
17 const uint8_t kExtraData[] = "input extra data";
18 const std::vector<uint8_t> kExtraDataVector(
19 &kExtraData[0], &kExtraData[0] + std::size(kExtraData));
21 AudioDecoderConfig input;
22 input.Initialize(AudioCodec::kAAC, kSampleFormatU8, CHANNEL_LAYOUT_SURROUND,
23 48000, kExtraDataVector, EncryptionScheme::kUnencrypted,
24 base::TimeDelta(), 0);
25 std::vector<uint8_t> data = mojom::AudioDecoderConfig::Serialize(&input);
26 AudioDecoderConfig output;
27 EXPECT_TRUE(mojom::AudioDecoderConfig::Deserialize(std::move(data), &output));
28 EXPECT_TRUE(output.Matches(input));
31 TEST(AudioDecoderConfigStructTraitsTest, EmptyExtraData) {
32 AudioDecoderConfig input;
33 input.Initialize(AudioCodec::kAAC, kSampleFormatU8, CHANNEL_LAYOUT_SURROUND,
34 48000, EmptyExtraData(), EncryptionScheme::kUnencrypted,
35 base::TimeDelta(), 0);
36 std::vector<uint8_t> data = mojom::AudioDecoderConfig::Serialize(&input);
37 AudioDecoderConfig output;
38 EXPECT_TRUE(mojom::AudioDecoderConfig::Deserialize(std::move(data), &output));
39 EXPECT_TRUE(output.Matches(input));
42 TEST(AudioDecoderConfigStructTraitsTest, Encrypted) {
43 AudioDecoderConfig input;
44 input.Initialize(AudioCodec::kAAC, kSampleFormatU8, CHANNEL_LAYOUT_SURROUND,
45 48000, EmptyExtraData(), EncryptionScheme::kCenc,
46 base::TimeDelta(), 0);
47 std::vector<uint8_t> data = mojom::AudioDecoderConfig::Serialize(&input);
48 AudioDecoderConfig output;
49 EXPECT_TRUE(mojom::AudioDecoderConfig::Deserialize(std::move(data), &output));
50 EXPECT_TRUE(output.Matches(input));
53 TEST(AudioDecoderConfigStructTraitsTest, WithProfile) {
54 AudioDecoderConfig input;
55 input.Initialize(AudioCodec::kAAC, kSampleFormatU8, CHANNEL_LAYOUT_SURROUND,
56 48000, EmptyExtraData(), EncryptionScheme::kUnencrypted,
57 base::TimeDelta(), 0);
58 input.set_profile(AudioCodecProfile::kXHE_AAC);
59 std::vector<uint8_t> data = mojom::AudioDecoderConfig::Serialize(&input);
60 AudioDecoderConfig output;
61 EXPECT_TRUE(mojom::AudioDecoderConfig::Deserialize(std::move(data), &output));
62 EXPECT_TRUE(output.Matches(input));
65 TEST(AudioDecoderConfigStructTraitsTest, DisableDiscardDecoderDelay) {
66 AudioDecoderConfig input;
67 input.Initialize(AudioCodec::kAAC, kSampleFormatU8, CHANNEL_LAYOUT_SURROUND,
68 48000, EmptyExtraData(), EncryptionScheme::kUnencrypted,
69 base::TimeDelta(), 0);
70 input.disable_discard_decoder_delay();
71 std::vector<uint8_t> data = mojom::AudioDecoderConfig::Serialize(&input);
72 AudioDecoderConfig output;
73 EXPECT_TRUE(mojom::AudioDecoderConfig::Deserialize(std::move(data), &output));
74 EXPECT_TRUE(output.Matches(input));
75 EXPECT_FALSE(output.should_discard_decoder_delay());
78 TEST(AudioDecoderConfigStructTraitsTest, TargetOutputChannelLayout) {
79 AudioDecoderConfig input;
80 input.Initialize(AudioCodec::kAAC, kSampleFormatU8, CHANNEL_LAYOUT_SURROUND,
81 48000, EmptyExtraData(), EncryptionScheme::kUnencrypted,
82 base::TimeDelta(), 0);
83 input.set_target_output_channel_layout(CHANNEL_LAYOUT_5_1);
84 input.set_target_output_sample_format(kSampleFormatDts);
85 std::vector<uint8_t> data = mojom::AudioDecoderConfig::Serialize(&input);
86 AudioDecoderConfig output;
87 EXPECT_TRUE(mojom::AudioDecoderConfig::Deserialize(std::move(data), &output));
88 EXPECT_TRUE(output.Matches(input));
89 EXPECT_EQ(output.target_output_channel_layout(), CHANNEL_LAYOUT_5_1);
90 EXPECT_EQ(output.target_output_sample_format(), kSampleFormatDts);
93 TEST(AudioDecoderConfigStructTraitsTest, AacExtraData) {
94 const uint8_t kAacExtraData[] = "aac extra data";
95 const std::vector<uint8_t> kAacExtraDataVector(
96 kAacExtraData, kAacExtraData + std::size(kAacExtraData));
98 AudioDecoderConfig input;
99 input.Initialize(AudioCodec::kAAC, kSampleFormatU8, CHANNEL_LAYOUT_SURROUND,
100 48000, EmptyExtraData(), EncryptionScheme::kUnencrypted,
101 base::TimeDelta(), 0);
102 input.set_aac_extra_data(kAacExtraDataVector);
103 std::vector<uint8_t> data = mojom::AudioDecoderConfig::Serialize(&input);
104 AudioDecoderConfig output;
105 EXPECT_TRUE(mojom::AudioDecoderConfig::Deserialize(std::move(data), &output));
106 EXPECT_TRUE(output.Matches(input));
107 EXPECT_EQ(output.aac_extra_data(), kAacExtraDataVector);