2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2016 Google LLC. All rights reserved.
|
2016-02-09 00:22:01 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2016-05-25 18:03:17 +00:00
|
|
|
#include "packager/media/codecs/ec3_audio_util.h"
|
2016-02-09 00:22:01 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-02-09 00:22:01 +00:00
|
|
|
namespace media {
|
|
|
|
|
2018-01-06 01:18:23 +00:00
|
|
|
TEST(EC3AudioUtilTest, ChannelTest1) {
|
2016-02-09 00:22:01 +00:00
|
|
|
// audio_coding_mode is 7, which is Left, Center, Right, Left surround, Right
|
|
|
|
// surround. No dependent substreams. LFE channel on.
|
2020-06-04 05:02:49 +00:00
|
|
|
const std::vector<uint8_t> ec3_data = {0, 0, 0, 0x0f, 0, 0x02, 0x10};
|
2018-01-06 01:18:23 +00:00
|
|
|
|
2016-02-09 00:22:01 +00:00
|
|
|
uint32_t channel_map;
|
2020-06-04 05:02:49 +00:00
|
|
|
uint32_t ec3_channel_mpeg_value;
|
|
|
|
uint32_t ec3_joc_complexity;
|
2018-01-06 01:18:23 +00:00
|
|
|
EXPECT_TRUE(CalculateEC3ChannelMap(ec3_data, &channel_map));
|
2016-02-09 00:22:01 +00:00
|
|
|
EXPECT_EQ(0xF801u, channel_map);
|
2018-01-06 01:18:23 +00:00
|
|
|
EXPECT_EQ(6u, GetEc3NumChannels(ec3_data));
|
2020-06-04 05:02:49 +00:00
|
|
|
EXPECT_TRUE(CalculateEC3ChannelMPEGValue(ec3_data, &ec3_channel_mpeg_value));
|
|
|
|
EXPECT_EQ(6u, ec3_channel_mpeg_value);
|
|
|
|
EXPECT_TRUE(GetEc3JocComplexity(ec3_data, &ec3_joc_complexity));
|
|
|
|
EXPECT_EQ(0u, ec3_joc_complexity);
|
2016-02-09 00:22:01 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 01:18:23 +00:00
|
|
|
TEST(EC3AudioUtilTest, ChannelTest2) {
|
2016-02-09 00:22:01 +00:00
|
|
|
// audio_coding_mode is 2, which is Left and Right. No dependent substreams.
|
|
|
|
// LFE channel off.
|
2018-01-06 01:18:23 +00:00
|
|
|
const std::vector<uint8_t> ec3_data = {0, 0, 0, 0x04, 0};
|
|
|
|
|
2016-02-09 00:22:01 +00:00
|
|
|
uint32_t channel_map;
|
2020-06-04 05:02:49 +00:00
|
|
|
uint32_t ec3_channel_mpeg_value;
|
|
|
|
uint32_t ec3_joc_complexity;
|
2018-01-06 01:18:23 +00:00
|
|
|
EXPECT_TRUE(CalculateEC3ChannelMap(ec3_data, &channel_map));
|
2016-02-09 00:22:01 +00:00
|
|
|
EXPECT_EQ(0xA000u, channel_map);
|
2018-01-06 01:18:23 +00:00
|
|
|
EXPECT_EQ(2u, GetEc3NumChannels(ec3_data));
|
2020-06-04 05:02:49 +00:00
|
|
|
EXPECT_TRUE(CalculateEC3ChannelMPEGValue(ec3_data, &ec3_channel_mpeg_value));
|
|
|
|
EXPECT_EQ(2u, ec3_channel_mpeg_value);
|
|
|
|
EXPECT_TRUE(GetEc3JocComplexity(ec3_data, &ec3_joc_complexity));
|
|
|
|
EXPECT_EQ(0u, ec3_joc_complexity);
|
2016-02-09 00:22:01 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 01:18:23 +00:00
|
|
|
TEST(EC3AudioUtilTest, ChannelTest3) {
|
2016-02-09 00:22:01 +00:00
|
|
|
// audio_coding_mode is 3, which is Left, Center, and Right. Dependent
|
|
|
|
// substreams layout is 0b100000011, which is Left center/ Right center pair,
|
|
|
|
// Left rear surround/ Right rear surround pair, LFE2 on. LFE channel on.
|
2018-01-06 01:18:23 +00:00
|
|
|
const std::vector<uint8_t> ec3_data = {0, 0, 0, 0x07, 0x07, 0x03};
|
|
|
|
|
2016-02-09 00:22:01 +00:00
|
|
|
uint32_t channel_map;
|
2020-06-04 05:02:49 +00:00
|
|
|
uint32_t ec3_channel_mpeg_value;
|
|
|
|
uint32_t ec3_joc_complexity;
|
2018-01-06 01:18:23 +00:00
|
|
|
EXPECT_TRUE(CalculateEC3ChannelMap(ec3_data, &channel_map));
|
2016-02-09 00:22:01 +00:00
|
|
|
EXPECT_EQ(0xE603u, channel_map);
|
2018-01-06 01:18:23 +00:00
|
|
|
EXPECT_EQ(9u, GetEc3NumChannels(ec3_data));
|
2020-06-04 05:02:49 +00:00
|
|
|
EXPECT_TRUE(CalculateEC3ChannelMPEGValue(ec3_data, &ec3_channel_mpeg_value));
|
|
|
|
EXPECT_EQ(0xFFFFFFFFu, ec3_channel_mpeg_value);
|
|
|
|
EXPECT_TRUE(GetEc3JocComplexity(ec3_data, &ec3_joc_complexity));
|
|
|
|
EXPECT_EQ(0u, ec3_joc_complexity);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(EC3AudioUtilTest, ChannelTest4) {
|
|
|
|
// audio_coding_mode is 7, which is Left, Center, Right, Left surround and
|
|
|
|
// Right surround. LFE channel on.
|
|
|
|
const std::vector<uint8_t> ec3_data = {0x14, 0x00, 0x20, 0x0f, 0x00, 0x01,
|
|
|
|
0x10};
|
|
|
|
|
|
|
|
uint32_t channel_map;
|
|
|
|
uint32_t ec3_channel_mpeg_value;
|
|
|
|
uint32_t ec3_joc_complexity;
|
|
|
|
EXPECT_TRUE(CalculateEC3ChannelMap(ec3_data, &channel_map));
|
|
|
|
EXPECT_EQ(0xF801u, channel_map);
|
|
|
|
EXPECT_EQ(6u, GetEc3NumChannels(ec3_data));
|
|
|
|
EXPECT_TRUE(CalculateEC3ChannelMPEGValue(ec3_data, &ec3_channel_mpeg_value));
|
|
|
|
EXPECT_EQ(6u, ec3_channel_mpeg_value);
|
|
|
|
EXPECT_TRUE(GetEc3JocComplexity(ec3_data, &ec3_joc_complexity));
|
|
|
|
EXPECT_EQ(16u, ec3_joc_complexity);
|
2016-02-09 00:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|