2014-04-15 23:51:32 +00:00
|
|
|
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-08-21 22:40:44 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2023-08-31 23:59:46 +00:00
|
|
|
#include <absl/strings/numbers.h>
|
|
|
|
#include <glog/logging.h>
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/formats/mp2t/adts_header.h>
|
|
|
|
#include <packager/utils/hex_parser.h>
|
2014-04-15 23:51:32 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const char kValidAdtsFrame[] =
|
|
|
|
"fff15080429ffcda004c61766335332e33352e30004258892a5361062403"
|
|
|
|
"d040000000001ff9055e9fe77ac56eb1677484e0ef0c3102a39daa8355a5"
|
|
|
|
"37ecab2b156e4ba73ceedb24ea51194e57c9385fa67eca8edc914902e852"
|
|
|
|
"3185b52299516e679fb3768aa9f13ccac5b257410080282c9a50318ec94e"
|
|
|
|
"ba24ea305bafab2b2beab16557ef9ecaa8f17bedea84788c8d42e4b3c65b"
|
|
|
|
"1e7ecae7528b909bc46c76cca73b906ec980ed9f32b25ecd28f43f9516de"
|
|
|
|
"3ff249f23bb9c93e64c4808195f284653c40592c1a8dc847f5f11791fd80"
|
|
|
|
"b18e02c1e1ed9f82c62a1f8ea0f5b6dbf2112c2202973b00de71bb49f906"
|
|
|
|
"ed1bc63768dda378c8f9c6ed1bb48f68dda378c9f68dda3768dda3768de3"
|
|
|
|
"23da3768de31bb492a5361062403d040000000001ff9055e9fe77ac56eb1"
|
|
|
|
"677484e0ef0c3102a39daa8355a537ecab2b156e4ba73ceedb24ea51194e"
|
|
|
|
"57c9385fa67eca8edc914902e8523185b52299516e679fb3768aa9f13cca"
|
|
|
|
"c5b257410080282c9a50318ec94eba24ea305bafab2b2beab16557ef9eca"
|
|
|
|
"a8f17bedea84788c8d42e4b3c65b1e7ecae7528b909bc46c76cca73b906e"
|
|
|
|
"c980ed9f32b25ecd28f43f9516de3ff249f23bb9c93e64c4808195f28465"
|
|
|
|
"3c40592c1a8dc847f5f11791fd80b18e02c1e1ed9f82c62a1f8ea0f5b6db"
|
|
|
|
"f2112c2202973b00de71bb49f906ed1bc63768dda378c8f9c6ed1bb48f68"
|
|
|
|
"dda378c9f68dda3768dda3768de323da3768de31bb4e";
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint8_t kExpectedAudioSpecificConfig[] = {0x12, 0x10};
|
2014-04-15 23:51:32 +00:00
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-04-15 23:51:32 +00:00
|
|
|
namespace media {
|
|
|
|
namespace mp2t {
|
|
|
|
|
|
|
|
class AdtsHeaderTest : public testing::Test {
|
|
|
|
public:
|
2015-07-22 23:40:45 +00:00
|
|
|
void SetUp() override {
|
2023-08-31 23:59:46 +00:00
|
|
|
ASSERT_TRUE(shaka::ValidHexStringToBytes(kValidAdtsFrame, &adts_frame_));
|
2014-04-15 23:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-09-30 21:52:21 +00:00
|
|
|
std::vector<uint8_t> adts_frame_;
|
2014-04-15 23:51:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(AdtsHeaderTest, ParseSuccess) {
|
2017-10-23 05:27:27 +00:00
|
|
|
const size_t kExpectedHeaderSize(7);
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint8_t kExpectedObjectType(2);
|
|
|
|
const uint32_t kExpectedSamplingFrequency(44100);
|
|
|
|
const uint8_t kExpectedNumChannels(2);
|
2014-04-15 23:51:32 +00:00
|
|
|
AdtsHeader adts_header;
|
2019-10-01 17:15:58 +00:00
|
|
|
EXPECT_EQ(adts_frame_.size(),
|
|
|
|
adts_header.GetFrameSizeWithoutParsing(adts_frame_.data(),
|
|
|
|
adts_frame_.size()));
|
2017-10-23 05:27:27 +00:00
|
|
|
ASSERT_TRUE(adts_header.Parse(adts_frame_.data(), adts_frame_.size()));
|
|
|
|
EXPECT_EQ(adts_frame_.size(), adts_header.GetFrameSize());
|
|
|
|
EXPECT_EQ(kExpectedHeaderSize, adts_header.GetHeaderSize());
|
2014-04-15 23:51:32 +00:00
|
|
|
EXPECT_EQ(kExpectedObjectType, adts_header.GetObjectType());
|
|
|
|
EXPECT_EQ(kExpectedSamplingFrequency, adts_header.GetSamplingFrequency());
|
|
|
|
EXPECT_EQ(kExpectedNumChannels, adts_header.GetNumChannels());
|
2014-09-30 21:52:21 +00:00
|
|
|
std::vector<uint8_t> audio_specific_config;
|
2017-10-23 05:27:27 +00:00
|
|
|
adts_header.GetAudioSpecificConfig(&audio_specific_config);
|
2023-08-31 23:59:46 +00:00
|
|
|
EXPECT_EQ(std::size(kExpectedAudioSpecificConfig),
|
2014-04-15 23:51:32 +00:00
|
|
|
audio_specific_config.size());
|
2014-09-30 21:52:21 +00:00
|
|
|
EXPECT_EQ(std::vector<uint8_t>(kExpectedAudioSpecificConfig,
|
|
|
|
kExpectedAudioSpecificConfig +
|
2023-08-31 23:59:46 +00:00
|
|
|
std::size(kExpectedAudioSpecificConfig)),
|
2014-09-30 21:52:21 +00:00
|
|
|
audio_specific_config);
|
2014-04-15 23:51:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 05:27:27 +00:00
|
|
|
TEST_F(AdtsHeaderTest, ParseVariousDataSize) {
|
2014-04-15 23:51:32 +00:00
|
|
|
AdtsHeader adts_header;
|
|
|
|
|
2017-10-23 05:27:27 +00:00
|
|
|
// Parse succeeds as long as the full header is provided.
|
|
|
|
EXPECT_TRUE(adts_header.Parse(adts_frame_.data(), adts_frame_.size() - 1));
|
|
|
|
const size_t header_size = adts_header.GetHeaderSize();
|
|
|
|
EXPECT_EQ(adts_frame_.size(), adts_header.GetFrameSize());
|
|
|
|
|
|
|
|
EXPECT_TRUE(adts_header.Parse(adts_frame_.data(), header_size));
|
|
|
|
EXPECT_EQ(adts_frame_.size(), adts_header.GetFrameSize());
|
|
|
|
EXPECT_EQ(header_size, adts_header.GetHeaderSize());
|
2014-04-15 23:51:32 +00:00
|
|
|
|
2017-10-23 05:27:27 +00:00
|
|
|
// Parse fails if there is not enough data (no full header).
|
|
|
|
EXPECT_FALSE(adts_header.Parse(adts_frame_.data(), 1));
|
|
|
|
EXPECT_FALSE(adts_header.Parse(adts_frame_.data(), header_size - 1));
|
2014-04-15 23:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace mp2t
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|