2013-09-24 01:35:40 +00:00
|
|
|
// Copyright (c) 2012 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.
|
|
|
|
|
2018-05-17 00:53:52 +00:00
|
|
|
#include "packager/media/codecs/es_descriptor.h"
|
|
|
|
|
|
|
|
#include <gmock/gmock.h>
|
2014-08-21 22:40:44 +00:00
|
|
|
#include <gtest/gtest.h>
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2019-01-04 23:49:57 +00:00
|
|
|
#include "packager/media/base/buffer_writer.h"
|
|
|
|
|
2018-05-17 00:53:52 +00:00
|
|
|
using ::testing::ElementsAre;
|
2019-01-04 23:49:57 +00:00
|
|
|
using ::testing::ElementsAreArray;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-09-24 01:35:40 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
TEST(ESDescriptorTest, SingleByteLengthTest) {
|
2018-05-17 00:53:52 +00:00
|
|
|
// clang-format off
|
|
|
|
const uint8_t kBuffer[] = {
|
|
|
|
// ESDescriptor tag with one byte size.
|
|
|
|
0x03, 0x19,
|
|
|
|
// ESDescriptor fields.
|
2020-07-15 21:14:15 +00:00
|
|
|
0x00, 0x00, 0x00,
|
2018-05-17 00:53:52 +00:00
|
|
|
// DecoderConfigDescriptor tag with one byte size.
|
|
|
|
0x04, 0x11,
|
|
|
|
// Object Type.
|
|
|
|
0x40,
|
|
|
|
// Three 4-byte fields: dummy, max bitrate, avg bitrate.
|
|
|
|
0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
// DecoderSpecificInfo tag with one byte size.
|
|
|
|
0x05, 0x02,
|
|
|
|
// DecoderSpecificInfo fields.
|
|
|
|
0x12, 0x10,
|
|
|
|
// SLConfig tag with one byte size.
|
|
|
|
0x06, 0x01,
|
|
|
|
// SLConfig fields.
|
|
|
|
0x02,
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
std::vector<uint8_t> data(std::begin(kBuffer), std::end(kBuffer));
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2018-05-17 00:53:52 +00:00
|
|
|
ESDescriptor es_desc;
|
2019-01-04 23:49:57 +00:00
|
|
|
const DecoderConfigDescriptor& decoder_config_descriptor =
|
|
|
|
es_desc.decoder_config_descriptor();
|
|
|
|
EXPECT_EQ(decoder_config_descriptor.object_type(), ObjectType::kForbidden);
|
2013-09-24 01:35:40 +00:00
|
|
|
EXPECT_TRUE(es_desc.Parse(data));
|
2018-05-17 00:53:52 +00:00
|
|
|
|
2019-01-04 23:49:57 +00:00
|
|
|
EXPECT_EQ(decoder_config_descriptor.object_type(), ObjectType::kISO_14496_3);
|
|
|
|
EXPECT_THAT(
|
|
|
|
decoder_config_descriptor.decoder_specific_info_descriptor().data(),
|
|
|
|
ElementsAre(0x12, 0x10));
|
|
|
|
|
|
|
|
BufferWriter writer;
|
|
|
|
es_desc.Write(&writer);
|
|
|
|
EXPECT_THAT(
|
|
|
|
std::vector<uint8_t>(writer.Buffer(), writer.Buffer() + writer.Size()),
|
|
|
|
ElementsAreArray(kBuffer));
|
2020-07-15 21:14:15 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(0u, es_desc.esid());
|
|
|
|
const size_t kEsIdOffset = 3;
|
|
|
|
const uint8_t kEsId = 5;
|
|
|
|
data[kEsIdOffset] = kEsId;
|
|
|
|
ASSERT_TRUE(es_desc.Parse(data));
|
|
|
|
EXPECT_EQ(kEsId, es_desc.esid());
|
|
|
|
|
|
|
|
writer.Clear();
|
|
|
|
es_desc.Write(&writer);
|
|
|
|
EXPECT_THAT(
|
|
|
|
std::vector<uint8_t>(writer.Buffer(), writer.Buffer() + writer.Size()),
|
|
|
|
ElementsAreArray(kBuffer));
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ESDescriptorTest, NonAACTest) {
|
2018-05-17 00:53:52 +00:00
|
|
|
// clang-format off
|
|
|
|
const uint8_t kBuffer[] = {
|
|
|
|
// ESDescriptor tag with one byte size.
|
|
|
|
0x03, 0x19,
|
|
|
|
// ESDescriptor fields.
|
2020-07-15 21:14:15 +00:00
|
|
|
0x00, 0x00, 0x00,
|
2018-05-17 00:53:52 +00:00
|
|
|
// DecoderConfigDescriptor tag with one byte size.
|
|
|
|
0x04, 0x11,
|
|
|
|
// Object Type.
|
|
|
|
0x66,
|
|
|
|
// Three 4-byte fields: dummy, max bitrate, avg bitrate.
|
|
|
|
0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
// DecoderSpecificInfo tag with one byte size.
|
|
|
|
0x05, 0x02,
|
|
|
|
// DecoderSpecificInfo fields.
|
|
|
|
0x12, 0x10,
|
|
|
|
// SLConfig tag with one byte size.
|
|
|
|
0x06, 0x01,
|
|
|
|
// SLConfig fields.
|
|
|
|
0x02,
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
std::vector<uint8_t> data(std::begin(kBuffer), std::end(kBuffer));
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2018-05-17 00:53:52 +00:00
|
|
|
ESDescriptor es_desc;
|
2013-09-24 01:35:40 +00:00
|
|
|
EXPECT_TRUE(es_desc.Parse(data));
|
|
|
|
|
2019-01-04 23:49:57 +00:00
|
|
|
const DecoderConfigDescriptor& decoder_config_descriptor =
|
|
|
|
es_desc.decoder_config_descriptor();
|
|
|
|
EXPECT_EQ(static_cast<int>(decoder_config_descriptor.object_type()), 0x66);
|
|
|
|
EXPECT_NE(decoder_config_descriptor.object_type(), ObjectType::kISO_14496_3);
|
|
|
|
EXPECT_THAT(
|
|
|
|
decoder_config_descriptor.decoder_specific_info_descriptor().data(),
|
|
|
|
ElementsAre(0x12, 0x10));
|
|
|
|
|
|
|
|
BufferWriter writer;
|
|
|
|
es_desc.Write(&writer);
|
|
|
|
EXPECT_THAT(
|
|
|
|
std::vector<uint8_t>(writer.Buffer(), writer.Buffer() + writer.Size()),
|
|
|
|
ElementsAreArray(kBuffer));
|
2018-05-17 00:53:52 +00:00
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2018-05-17 00:53:52 +00:00
|
|
|
TEST(ESDescriptorTest, NonAACWithoutDecoderSpecificInfoTagTest) {
|
|
|
|
// clang-format off
|
|
|
|
const uint8_t kBuffer[] = {
|
|
|
|
// ESDescriptor tag with one byte size.
|
|
|
|
0x03, 0x15,
|
|
|
|
// ESDescriptor fields.
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
// DecoderConfigDescriptor tag with one byte size.
|
|
|
|
0x04, 0x0d,
|
|
|
|
// Object Type.
|
|
|
|
0x6b,
|
|
|
|
// Three 4-byte fields: dummy, max bitrate, avg bitrate.
|
|
|
|
0x15, 0x00, 0x01, 0xe0, 0x00, 0x02, 0x85, 0x00, 0x00, 0x02, 0x71, 0x00,
|
|
|
|
// SLConfig tag with one byte size.
|
|
|
|
0x06, 0x01,
|
|
|
|
// SLConfig fields.
|
|
|
|
0x02,
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
std::vector<uint8_t> data(std::begin(kBuffer), std::end(kBuffer));
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2018-05-17 00:53:52 +00:00
|
|
|
ESDescriptor es_desc;
|
2013-09-24 01:35:40 +00:00
|
|
|
EXPECT_TRUE(es_desc.Parse(data));
|
|
|
|
|
2019-01-04 23:49:57 +00:00
|
|
|
const DecoderConfigDescriptor& decoder_config_descriptor =
|
|
|
|
es_desc.decoder_config_descriptor();
|
|
|
|
EXPECT_EQ(static_cast<int>(decoder_config_descriptor.object_type()), 0x6b);
|
|
|
|
EXPECT_EQ(decoder_config_descriptor.max_bitrate(), 0x28500u);
|
|
|
|
EXPECT_EQ(decoder_config_descriptor.avg_bitrate(), 0x27100u);
|
|
|
|
EXPECT_THAT(
|
|
|
|
decoder_config_descriptor.decoder_specific_info_descriptor().data(),
|
|
|
|
ElementsAre());
|
2018-05-17 00:53:52 +00:00
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2022-03-07 19:56:34 +00:00
|
|
|
// https://github.com/shaka-project/shaka-packager/issues/536.
|
2019-01-04 23:49:57 +00:00
|
|
|
TEST(ESDescriptorTest, Issue536) {
|
2018-05-17 00:53:52 +00:00
|
|
|
// clang-format off
|
2019-01-04 23:49:57 +00:00
|
|
|
const uint8_t kInput[] = {
|
|
|
|
// ESDescriptor tag with size.
|
|
|
|
0x03, 0x80, 0x80, 0x80, 0x70,
|
2018-05-17 00:53:52 +00:00
|
|
|
// ESDescriptor fields.
|
2019-01-04 23:49:57 +00:00
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
// DecoderConfigDescriptor tag with size.
|
|
|
|
0x04, 0x80, 0x80, 0x80, 0x62,
|
2018-05-17 00:53:52 +00:00
|
|
|
// Object Type.
|
|
|
|
0x40,
|
|
|
|
// Three 4-byte fields: dummy, max bitrate, avg bitrate.
|
2019-01-04 23:49:57 +00:00
|
|
|
0x15, 0x00, 0x30, 0x00, 0x00, 0x01, 0xF4, 0x00,
|
|
|
|
0x00, 0x01, 0xF4, 0x00,
|
|
|
|
// DecoderSpecificInfo tag with size.
|
|
|
|
0x05, 0x80, 0x80, 0x80, 0x50,
|
2018-05-17 00:53:52 +00:00
|
|
|
// DecoderSpecificInfo fields.
|
2019-01-04 23:49:57 +00:00
|
|
|
0x11, 0x90, 0x08, 0xC4, 0x00, 0x00, 0x20, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
// SLConfig tag with size.
|
|
|
|
0x06, 0x80, 0x80, 0x80, 0x01,
|
|
|
|
// SLConfig fields.
|
|
|
|
0x02,
|
|
|
|
};
|
|
|
|
const uint8_t kOutput[] = {
|
|
|
|
// ESDescriptor tag with size.
|
|
|
|
0x03, 0x67,
|
|
|
|
// ESDescriptor fields.
|
|
|
|
0x00, 0x00, 0x00,
|
|
|
|
// DecoderConfigDescriptor tag with size.
|
|
|
|
0x04, 0x5F,
|
|
|
|
// Object Type.
|
|
|
|
0x40,
|
|
|
|
// Three 4-byte fields: dummy, max bitrate, avg bitrate.
|
|
|
|
0x15, 0x00, 0x30, 0x00, 0x00, 0x01, 0xF4, 0x00,
|
|
|
|
0x00, 0x01, 0xF4, 0x00,
|
|
|
|
// DecoderSpecificInfo tag with size.
|
|
|
|
0x05, 0x50,
|
|
|
|
// DecoderSpecificInfo fields.
|
|
|
|
0x11, 0x90, 0x08, 0xC4, 0x00, 0x00, 0x20, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
// SLConfig tag with size.
|
2018-05-17 00:53:52 +00:00
|
|
|
0x06, 0x01,
|
|
|
|
// SLConfig fields.
|
|
|
|
0x02,
|
|
|
|
};
|
|
|
|
// clang-format on
|
2019-01-04 23:49:57 +00:00
|
|
|
std::vector<uint8_t> data(std::begin(kInput), std::end(kInput));
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2018-05-17 00:53:52 +00:00
|
|
|
ESDescriptor es_desc;
|
2013-09-24 01:35:40 +00:00
|
|
|
EXPECT_TRUE(es_desc.Parse(data));
|
2018-05-17 00:53:52 +00:00
|
|
|
|
2019-01-04 23:49:57 +00:00
|
|
|
BufferWriter writer;
|
|
|
|
es_desc.Write(&writer);
|
|
|
|
EXPECT_THAT(
|
|
|
|
std::vector<uint8_t>(writer.Buffer(), writer.Buffer() + writer.Size()),
|
|
|
|
ElementsAreArray(kOutput));
|
|
|
|
}
|
|
|
|
|
|
|
|
class DescriptorLengthTest : public testing::Test {
|
|
|
|
public:
|
|
|
|
void TestReadWrite(const std::vector<uint8_t>& input,
|
|
|
|
const std::vector<uint8_t>& expected_output) {
|
|
|
|
DecoderSpecificInfoDescriptor desc;
|
|
|
|
EXPECT_TRUE(desc.Parse(input));
|
|
|
|
|
|
|
|
BufferWriter writer;
|
|
|
|
desc.Write(&writer);
|
|
|
|
EXPECT_THAT(
|
|
|
|
std::vector<uint8_t>(writer.Buffer(), writer.Buffer() + writer.Size()),
|
|
|
|
ElementsAreArray(expected_output));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Use DecoderSpecificInfo descriptor for length testing.
|
|
|
|
|
|
|
|
TEST_F(DescriptorLengthTest, OneByteLengthData) {
|
|
|
|
const uint8_t kBuffer[] = {0x05, 0x02, 0x12, 0x10};
|
|
|
|
std::vector<uint8_t> data(std::begin(kBuffer), std::end(kBuffer));
|
|
|
|
TestReadWrite(data, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DescriptorLengthTest, TwoBytesLengthForOneByteLengthData) {
|
|
|
|
const uint8_t kInput[] = {0x05, 0x80, 0x02, 0x12, 0x10};
|
|
|
|
const uint8_t kOutput[] = {0x05, 0x02, 0x12, 0x10};
|
|
|
|
std::vector<uint8_t> input(std::begin(kInput), std::end(kInput));
|
|
|
|
std::vector<uint8_t> output(std::begin(kOutput), std::end(kOutput));
|
|
|
|
TestReadWrite(input, output);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DescriptorLengthTest, ThreeBytesLengthForOneByteLengthData) {
|
|
|
|
const uint8_t kInput[] = {0x05, 0x80, 0x80, 0x02, 0x12, 0x10};
|
|
|
|
const uint8_t kOutput[] = {0x05, 0x02, 0x12, 0x10};
|
|
|
|
std::vector<uint8_t> input(std::begin(kInput), std::end(kInput));
|
|
|
|
std::vector<uint8_t> output(std::begin(kOutput), std::end(kOutput));
|
|
|
|
TestReadWrite(input, output);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DescriptorLengthTest, FourBytesLengthForOneByteLengthData) {
|
|
|
|
const uint8_t kInput[] = {0x05, 0x80, 0x80, 0x80, 0x02, 0x12, 0x10};
|
|
|
|
const uint8_t kOutput[] = {0x05, 0x02, 0x12, 0x10};
|
|
|
|
std::vector<uint8_t> input(std::begin(kInput), std::end(kInput));
|
|
|
|
std::vector<uint8_t> output(std::begin(kOutput), std::end(kOutput));
|
|
|
|
TestReadWrite(input, output);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DescriptorLengthTest, TwoBytesLengthData) {
|
|
|
|
const uint8_t kBuffer[] = {
|
|
|
|
0x05, 0x81, 0x02, 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00,
|
|
|
|
};
|
|
|
|
std::vector<uint8_t> input(std::begin(kBuffer), std::end(kBuffer));
|
|
|
|
std::vector<uint8_t> output(std::begin(kBuffer), std::end(kBuffer));
|
|
|
|
TestReadWrite(input, output);
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|