chromium/media/formats/webm/webm_cluster_parser_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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 {

// Matchers for verifying common media log entry strings.
MATCHER_P(OpusPacketDurationTooHigh, actual_duration_ms, "") {}

MATCHER_P2(WebMBlockDurationMismatchesOpusDuration,
           block_duration_ms,
           opus_duration_ms,
           "") {}

namespace {

// Timecode scale for millisecond timestamps.
const int kTimecodeScale =;

const int kAudioTrackNum =;
const int kVideoTrackNum =;
const int kTextTrackNum =;
constexpr double kTestAudioFrameDefaultDurationInMs =;
constexpr double kTestVideoFrameDefaultDurationInMs =;

// Test duration defaults must differ from parser estimation defaults to know
// which durations parser used when emitting buffers.
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) {}

// Creates a Cluster with one encrypted Block. |bytes_to_write| is number of
// bytes of the encrypted frame to write.
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) {}

}  // namespace

class WebMClusterParserTest : public testing::Test {};

TEST_F(WebMClusterParserTest, HeldBackBufferHoldsBackAllTracks) {}

TEST_F(WebMClusterParserTest, Reset) {}

TEST_F(WebMClusterParserTest, ParseClusterWithSingleCall) {}

TEST_F(WebMClusterParserTest, ParseClusterWithMultipleCalls) {}

// Verify that both BlockGroups with the BlockDuration before the Block
// and BlockGroups with the BlockDuration after the Block are supported
// correctly.
// Note: Raw bytes are use here because ClusterBuilder only generates
// one of these scenarios.
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) {}

// TODO(wolenetz): Is parser behavior correct? See http://crbug.com/363433.
TEST_F(WebMClusterParserTest,
       ParseWithDefaultDurationsBlockGroupsWithoutDurations) {}

// Verify the parser can handle block timestamps that are negative
// relative-to-cluster and to absolute time. With BlockDurations provided, there
// is no buffer duration estimation, and the ready-buffer extraction bounds are
// always maximal, for both a partial cluster and a full cluster parse.
TEST_F(WebMClusterParserTest,
       ParseClusterWithNegativeBlockTimestampsAndWithBlockDurations) {}

// Verify the parser can handle block timestamps that are negative
// relative-to-cluster and to absolute time. With neither BlockDurations nor
// DefaultDuration provided, all blocks' durations are derived from interblock
// timestamps in the track or estimated for the last block in the each track in
// the cluster, requiring holding back the last block in each track (unless the
// cluster is fully parsed to completion) so it can get estimated duration based
// on the next block in that track in the cluster. The ready-buffer extraction
// methods are driven by the test block to have negative upper-bounds in the
// partial-block parse in this case.
TEST_F(WebMClusterParserTest,
       ParseClusterWithNegativeBlockTimestampsAndWithoutDurations) {}

TEST_F(WebMClusterParserTest,
       ParseDegenerateClusterYieldsHardcodedEstimatedDurations) {}

TEST_F(WebMClusterParserTest,
       ParseDegenerateClusterWithDefaultDurationsYieldsDefaultDurations) {}

TEST_F(WebMClusterParserTest, ReadOpusDurationsSimpleBlockAtEndOfCluster) {}

TEST_F(WebMClusterParserTest, PreferOpusDurationsOverBlockDurations) {}

// Tests that BlockDuration is used to set duration on buffer rather than
// encoded duration in Opus packet (or hard coded duration estimates). Encoded
// Opus duration is usually preferred but cannot be known when encrypted.
TEST_F(WebMClusterParserTest, DontReadEncodedDurationWhenEncrypted) {}

}  // namespace media