| Index: media/formats/mp2t/es_parser_adts_unittest.cc
|
| diff --git a/media/formats/mp2t/es_parser_adts_unittest.cc b/media/formats/mp2t/es_parser_adts_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0fb7e5f88d6ba6a6c2e4ccc2498d2f66ee17bb31
|
| --- /dev/null
|
| +++ b/media/formats/mp2t/es_parser_adts_unittest.cc
|
| @@ -0,0 +1,126 @@
|
| +// 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.
|
| +
|
| +#include <algorithm>
|
| +#include <vector>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/command_line.h"
|
| +#include "base/files/memory_mapped_file.h"
|
| +#include "base/logging.h"
|
| +#include "base/path_service.h"
|
| +#include "base/time/time.h"
|
| +#include "media/base/buffers.h"
|
| +#include "media/base/stream_parser_buffer.h"
|
| +#include "media/base/test_data_util.h"
|
| +#include "media/formats/mp2t/es_parser_adts.h"
|
| +#include "media/formats/mp2t/es_parser_test_helper.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace media {
|
| +class AudioDecoderConfig;
|
| +
|
| +namespace mp2t {
|
| +
|
| +namespace {
|
| +
|
| +std::vector<Packet> GenerateFixedSizePesPacket(
|
| + const std::vector<uint8>& stream, size_t pes_size) {
|
| + std::vector<Packet> pes_packets;
|
| +
|
| + Packet cur_pes_packet;
|
| + cur_pes_packet.offset = 0;
|
| + cur_pes_packet.pts = kNoTimestamp();
|
| + while (cur_pes_packet.offset < stream.size()) {
|
| + pes_packets.push_back(cur_pes_packet);
|
| + cur_pes_packet.offset += pes_size;
|
| + }
|
| + ComputePacketSize(&pes_packets, stream.size());
|
| +
|
| + return pes_packets;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +class EsParserAdtsTest : public testing::Test {
|
| + public:
|
| + EsParserAdtsTest();
|
| + virtual ~EsParserAdtsTest() {}
|
| +
|
| + protected:
|
| + void LoadStream(const char* filename);
|
| + bool Process(const std::vector<Packet>& pes_packets, bool force_timing);
|
| +
|
| + // ADTS stream.
|
| + std::vector<uint8> stream_;
|
| +
|
| + // Number of different audio configs in the ADTS stream.
|
| + size_t config_count_;
|
| +
|
| + // Number of buffers generated while parsing the ADTS stream.
|
| + size_t buffer_count_;
|
| +
|
| + private:
|
| + void NewAudioConfig(const AudioDecoderConfig& config);
|
| + void EmitBuffer(scoped_refptr<StreamParserBuffer> buffer);
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(EsParserAdtsTest);
|
| +};
|
| +
|
| +EsParserAdtsTest::EsParserAdtsTest()
|
| + : config_count_(0),
|
| + buffer_count_(0) {
|
| +}
|
| +
|
| +void EsParserAdtsTest::LoadStream(const char* filename) {
|
| + base::FilePath file_path = GetTestDataFilePath(filename);
|
| +
|
| + base::MemoryMappedFile stream;
|
| + ASSERT_TRUE(stream.Initialize(file_path))
|
| + << "Couldn't open stream file: " << file_path.MaybeAsASCII();
|
| +
|
| + stream_.resize(stream.length());
|
| + memcpy(stream_.data(), stream.data(), stream_.size());
|
| +}
|
| +
|
| +bool EsParserAdtsTest::Process(
|
| + const std::vector<Packet>& pes_packets,
|
| + bool force_timing) {
|
| + EsParserAdts es_parser(
|
| + base::Bind(&EsParserAdtsTest::NewAudioConfig, base::Unretained(this)),
|
| + base::Bind(&EsParserAdtsTest::EmitBuffer, base::Unretained(this)),
|
| + false);
|
| +
|
| + return ProcessPesPackets(&es_parser, stream_, pes_packets, force_timing);
|
| +}
|
| +
|
| +void EsParserAdtsTest::NewAudioConfig(const AudioDecoderConfig& config) {
|
| + config_count_++;
|
| +}
|
| +
|
| +void EsParserAdtsTest::EmitBuffer(scoped_refptr<StreamParserBuffer> buffer) {
|
| + buffer_count_++;
|
| +}
|
| +
|
| +TEST_F(EsParserAdtsTest, NoInitialPts) {
|
| + LoadStream("bear.adts");
|
| + std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(stream_, 512);
|
| + EXPECT_FALSE(Process(pes_packets, false));
|
| + EXPECT_EQ(0u, buffer_count_);
|
| +}
|
| +
|
| +TEST_F(EsParserAdtsTest, SinglePts) {
|
| + LoadStream("bear.adts");
|
| +
|
| + std::vector<Packet> pes_packets = GenerateFixedSizePesPacket(stream_, 512);
|
| + pes_packets.front().pts = base::TimeDelta::FromSeconds(10);
|
| +
|
| + EXPECT_TRUE(Process(pes_packets, false));
|
| + EXPECT_EQ(1u, config_count_);
|
| + EXPECT_EQ(45u, buffer_count_);
|
| +}
|
| +
|
| +} // namespace mp2t
|
| +} // namespace media
|
| +
|
|
|