#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/formats/webm/webm_cluster_parser.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <cstdlib>
#include <memory>
#include <string>
#include <vector>
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/decrypt_config.h"
#include "media/base/mock_media_log.h"
#include "media/base/test_helpers.h"
#include "media/base/timestamp_constants.h"
#include "media/formats/webm/cluster_builder.h"
#include "media/formats/webm/opus_packet_builder.h"
#include "media/formats/webm/webm_constants.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
HasSubstr;
InSequence;
Return;
StrictMock;
Mock;
_;
namespace media {
MATCHER_P(OpusPacketDurationTooHigh, actual_duration_ms, "") { … }
MATCHER_P2(WebMBlockDurationMismatchesOpusDuration,
block_duration_ms,
opus_duration_ms,
"") { … }
namespace {
const int kTimecodeScale = …;
const int kAudioTrackNum = …;
const int kVideoTrackNum = …;
const int kTextTrackNum = …;
constexpr double kTestAudioFrameDefaultDurationInMs = …;
constexpr double kTestVideoFrameDefaultDurationInMs = …;
static_assert …;
static_assert …;
struct BlockInfo { … };
const BlockInfo kDefaultBlockInfo[] = …;
const uint8_t kEncryptedFrame[] = …;
std::unique_ptr<Cluster> CreateCluster(int timecode,
const BlockInfo* block_info,
int block_count) { … }
std::unique_ptr<Cluster> CreateEncryptedCluster(int bytes_to_write) { … }
bool VerifyBuffers(const StreamParser::BufferQueueMap& buffer_queue_map,
const BlockInfo* block_info,
int block_count) { … }
bool VerifyBuffers(const std::unique_ptr<WebMClusterParser>& parser,
const BlockInfo* block_info,
int block_count) { … }
void VerifyEncryptedBuffer(scoped_refptr<StreamParserBuffer> buffer) { … }
void AppendToEnd(const StreamParser::BufferQueue& src,
StreamParser::BufferQueue* dest) { … }
}
class WebMClusterParserTest : public testing::Test { … };
TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) { … }
TEST_F(WebMClusterParserTest, Reset) { … }
TEST_F(WebMClusterParserTest, ParseClusterWithSingleCall) { … }
TEST_F(WebMClusterParserTest, ParseClusterWithMultipleCalls) { … }
TEST_F(WebMClusterParserTest, ParseBlockGroup) { … }
TEST_F(WebMClusterParserTest, ParseSimpleBlockAndBlockGroupMixture) { … }
TEST_F(WebMClusterParserTest, IgnoredTracks) { … }
TEST_F(WebMClusterParserTest, ParseEncryptedBlock) { … }
TEST_F(WebMClusterParserTest, ParseBadEncryptedBlock) { … }
TEST_F(WebMClusterParserTest, ParseInvalidZeroSizedCluster) { … }
TEST_F(WebMClusterParserTest, ParseInvalidUnknownButActuallyZeroSizedCluster) { … }
TEST_F(WebMClusterParserTest, ParseWithDefaultDurationsSimpleBlocks) { … }
TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsSimpleBlocks) { … }
TEST_F(WebMClusterParserTest, ParseWithoutAnyDurationsBlockGroups) { … }
TEST_F(WebMClusterParserTest,
ParseWithDefaultDurationsBlockGroupsWithoutDurations) { … }
TEST_F(WebMClusterParserTest,
ParseClusterWithNegativeBlockTimestampsAndWithBlockDurations) { … }
TEST_F(WebMClusterParserTest,
ParseClusterWithNegativeBlockTimestampsAndWithoutDurations) { … }
TEST_F(WebMClusterParserTest,
ParseDegenerateClusterYieldsHardcodedEstimatedDurations) { … }
TEST_F(WebMClusterParserTest,
ParseDegenerateClusterWithDefaultDurationsYieldsDefaultDurations) { … }
TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) { … }
TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) { … }
TEST_F(WebMClusterParserTest, DontReadEncodedDurationWhenEncrypted) { … }
}