blob: 3dccf806a1c6b7a06b526c24ae589da76ed6f876 [file] [log] [blame]
// Copyright 2018 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 "cobalt/media/formats/webm/webm_video_client.h"
#include "cobalt/media/base/media_util.h"
#include "cobalt/media/base/mock_media_log.h"
#include "cobalt/media/base/video_decoder_config.h"
#include "cobalt/media/formats/webm/webm_constants.h"
using testing::StrictMock;
namespace cobalt {
namespace media {
namespace {
const math::Size kCodedSize(321, 243);
struct CodecTestParams {
VideoCodecProfile profile;
const std::vector<uint8_t> codec_private;
} // namespace
CodecTestParams kCodecTestParams[] = {
// Valid VP9 Profile 2 example, extracted out of a sample file at
{0x01, 0x01, 0x02, 0x02, 0x01, 0x0a, 0x3, 0x1, 0xa, 0x4, 0x1, 0x1}},
// Invalid VP9 CodecPrivate: too short.
{VP9PROFILE_PROFILE0, {0x01, 0x01}},
// Invalid VP9 CodecPrivate: wrong field id.
{VP9PROFILE_PROFILE0, {0x77, 0x01, 0x02}},
// Invalid VP9 CodecPrivate: wrong field length.
{VP9PROFILE_PROFILE0, {0x01, 0x75, 0x02}},
// Invalid VP9 CodecPrivate: wrong Profile (can't be > 3).
{VP9PROFILE_PROFILE0, {0x01, 0x01, 0x34}}};
class WebMVideoClientTest : public testing::TestWithParam<CodecTestParams> {
: media_log_(new StrictMock<MockMediaLog>()),
webm_video_client_(media_log_) {
// Simulate configuring width and height in the |webm_video_client_|.
webm_video_client_.OnUInt(kWebMIdPixelWidth, kCodedSize.width());
webm_video_client_.OnUInt(kWebMIdPixelHeight, kCodedSize.height());
scoped_refptr<StrictMock<MockMediaLog>> media_log_;
WebMVideoClient webm_video_client_;
TEST_P(WebMVideoClientTest, InitializeConfigVP9Profiles) {
const std::string kCodecId = "V_VP9";
const VideoCodecProfile profile = GetParam().profile;
const std::vector<uint8_t> codec_private = GetParam().codec_private;
VideoDecoderConfig config;
EXPECT_TRUE(webm_video_client_.InitializeConfig(kCodecId, codec_private,
EncryptionScheme(), &config));
VideoDecoderConfig expected_config(
kCodecVP9, profile, PIXEL_FORMAT_YV12, COLOR_SPACE_HD_REC709, kCodedSize,
math::Rect(kCodedSize), kCodedSize, codec_private, Unencrypted());
<< "Config (" << config.AsHumanReadableString()
<< ") does not match expected ("
<< expected_config.AsHumanReadableString() << ")";
INSTANTIATE_TEST_CASE_P(/* No prefix. */, WebMVideoClientTest,
} // namespace media
} // namespace cobalt