Commit 6649db74 authored by liberato@chromium.org's avatar liberato@chromium.org Committed by Commit Bot

Add media::SupportedVideoDecoderConfig

This CL adds SupportedVideoDecoderConfig to match the mojom struct.
It also adds a struct traits for them, and converts the existing
mojo code to use the media:: rather than the mojom:: version.

This will make it easier for {D3D11, MediaCodec}VideoDecoder to
return their media::SupportedVideoDecoderConfigs, since they cannot
use mojo directly.

Bug: 918029
Change-Id: Id0403ccadaa1b3fbbb310f01fd9b3a7bebc92ba7
Reviewed-on: https://chromium-review.googlesource.com/c/1392350
Commit-Queue: Frank Liberato <liberato@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619729}
parent 72508a5f
......@@ -136,10 +136,9 @@ void GpuVideoAcceleratorFactoriesImpl::BindOnTaskRunner(
}
void GpuVideoAcceleratorFactoriesImpl::OnSupportedDecoderConfigs(
std::vector<media::mojom::SupportedVideoDecoderConfigPtr>
supported_configs) {
const std::vector<media::SupportedVideoDecoderConfig>& supported_configs) {
base::AutoLock lock(supported_decoder_configs_lock_);
supported_decoder_configs_ = std::move(supported_configs);
supported_decoder_configs_ = supported_configs;
video_decoder_.reset();
}
......@@ -200,18 +199,9 @@ bool GpuVideoAcceleratorFactoriesImpl::IsDecoderConfigSupported(
if (!supported_decoder_configs_)
return true;
for (const media::mojom::SupportedVideoDecoderConfigPtr& supported :
*supported_decoder_configs_) {
if (config.profile() >= supported->profile_min &&
config.profile() <= supported->profile_max &&
config.coded_size().width() >= supported->coded_size_min.width() &&
config.coded_size().width() <= supported->coded_size_max.width() &&
config.coded_size().height() >= supported->coded_size_min.height() &&
config.coded_size().height() <= supported->coded_size_max.height() &&
(config.is_encrypted() ? supported->allow_encrypted
: !supported->require_encrypted)) {
for (const auto& supported : *supported_decoder_configs_) {
if (supported.Matches(config))
return true;
}
}
return false;
}
......
......@@ -158,8 +158,7 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl
void SetContextProviderLostOnMainThread();
void OnSupportedDecoderConfigs(
std::vector<media::mojom::SupportedVideoDecoderConfigPtr>
supported_configs);
const std::vector<media::SupportedVideoDecoderConfig>& supported_configs);
const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
......@@ -193,7 +192,10 @@ class CONTENT_EXPORT GpuVideoAcceleratorFactoriesImpl
// SupportedDecoderConfigs state.
mojo::InterfacePtr<media::mojom::VideoDecoder> video_decoder_;
base::Lock supported_decoder_configs_lock_;
base::Optional<std::vector<media::mojom::SupportedVideoDecoderConfigPtr>>
// If the Optional is empty, then we have not yet gotten the configs. If the
// Optional contains an empty vector, then we have gotten the result and there
// are no supported configs.
base::Optional<std::vector<media::SupportedVideoDecoderConfig>>
supported_decoder_configs_ GUARDED_BY(supported_decoder_configs_lock_);
// For sending requests to allocate shared memory in the Browser process.
......
// Copyright 2019 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 "media/mojo/interfaces/supported_video_decoder_config_struct_traits.h"
namespace mojo {
// static
bool StructTraits<media::mojom::SupportedVideoDecoderConfigDataView,
media::SupportedVideoDecoderConfig>::
Read(media::mojom::SupportedVideoDecoderConfigDataView input,
media::SupportedVideoDecoderConfig* output) {
if (!input.ReadProfileMin(&output->profile_min))
return false;
if (!input.ReadProfileMax(&output->profile_max))
return false;
if (!input.ReadCodedSizeMin(&output->coded_size_min))
return false;
if (!input.ReadCodedSizeMax(&output->coded_size_max))
return false;
output->allow_encrypted = input.allow_encrypted();
output->require_encrypted = input.require_encrypted();
return true;
}
} // namespace mojo
// Copyright 2019 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.
#ifndef MEDIA_MOJO_INTERFACES_SUPPORTED_VIDEO_DECODER_CONFIG_STRUCT_TRAITS_H_
#define MEDIA_MOJO_INTERFACES_SUPPORTED_VIDEO_DECODER_CONFIG_STRUCT_TRAITS_H_
#include "media/base/ipc/media_param_traits.h"
#include "media/mojo/interfaces/media_types.mojom.h"
#include "media/mojo/interfaces/video_decoder.mojom.h"
#include "media/video/supported_video_decoder_config.h"
#include "ui/gfx/geometry/mojo/geometry_struct_traits.h"
namespace mojo {
template <>
struct StructTraits<media::mojom::SupportedVideoDecoderConfigDataView,
media::SupportedVideoDecoderConfig> {
static media::VideoCodecProfile profile_min(
const media::SupportedVideoDecoderConfig& input) {
return input.profile_min;
}
static media::VideoCodecProfile profile_max(
const media::SupportedVideoDecoderConfig& input) {
return input.profile_max;
}
static const gfx::Size& coded_size_min(
const media::SupportedVideoDecoderConfig& input) {
return input.coded_size_min;
}
static const gfx::Size& coded_size_max(
const media::SupportedVideoDecoderConfig& input) {
return input.coded_size_max;
}
static bool allow_encrypted(const media::SupportedVideoDecoderConfig& input) {
return input.allow_encrypted;
}
static bool require_encrypted(
const media::SupportedVideoDecoderConfig& input) {
return input.require_encrypted;
}
static bool Read(media::mojom::SupportedVideoDecoderConfigDataView input,
media::SupportedVideoDecoderConfig* output);
};
} // namespace mojo
#endif // MEDIA_MOJO_INTERFACES_SUPPORTED_VIDEO_DECODER_CONFIG_STRUCT_TRAITS_H_
......@@ -4,12 +4,26 @@
mojom = "//media/mojo/interfaces/video_decoder.mojom"
public_headers = [ "//media/base/overlay_info.h" ]
public_headers = [
"//media/base/overlay_info.h",
"//media/video/supported_video_decoder_config.h",
]
traits_headers = [ "//media/base/ipc/media_param_traits_macros.h" ]
traits_headers = [
"//media/base/ipc/media_param_traits_macros.h",
"//media/mojo/interfaces/supported_video_decoder_config_struct_traits.h",
]
sources = [
"supported_video_decoder_config_struct_traits.cc",
"supported_video_decoder_config_struct_traits.h",
]
deps = [
"//media/gpu/ipc/common",
]
type_mappings = [ "media.mojom.OverlayInfo=media::OverlayInfo" ]
type_mappings = [
"media.mojom.OverlayInfo=media::OverlayInfo",
"media.mojom.SupportedVideoDecoderConfig=media::SupportedVideoDecoderConfig",
]
......@@ -102,7 +102,7 @@ std::unique_ptr<AudioDecoder> GpuMojoMediaClient::CreateAudioDecoder(
#endif // defined(OS_ANDROID)
}
std::vector<mojom::SupportedVideoDecoderConfigPtr>
std::vector<SupportedVideoDecoderConfig>
GpuMojoMediaClient::GetSupportedVideoDecoderConfigs() {
// TODO(liberato): Implement for D3D11VideoDecoder and MediaCodecVideoDecoder.
VideoDecodeAccelerator::Capabilities capabilities =
......@@ -113,9 +113,9 @@ GpuMojoMediaClient::GetSupportedVideoDecoderConfigs() {
capabilities.flags &
VideoDecodeAccelerator::Capabilities::SUPPORTS_ENCRYPTED_STREAMS;
std::vector<mojom::SupportedVideoDecoderConfigPtr> supported_configs;
std::vector<SupportedVideoDecoderConfig> supported_configs;
for (const auto& supported_profile : capabilities.supported_profiles) {
supported_configs.push_back(mojom::SupportedVideoDecoderConfig::New(
supported_configs.push_back(SupportedVideoDecoderConfig(
supported_profile.profile, // profile_min
supported_profile.profile, // profile_max
supported_profile.min_resolution, // coded_size_min
......
......@@ -39,8 +39,8 @@ class GpuMojoMediaClient : public MojoMediaClient {
~GpuMojoMediaClient() final;
// MojoMediaClient implementation.
std::vector<mojom::SupportedVideoDecoderConfigPtr>
GetSupportedVideoDecoderConfigs() final;
std::vector<SupportedVideoDecoderConfig> GetSupportedVideoDecoderConfigs()
final;
void Initialize(service_manager::Connector* connector) final;
std::unique_ptr<AudioDecoder> CreateAudioDecoder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) final;
......
......@@ -28,9 +28,9 @@ std::unique_ptr<AudioDecoder> MojoMediaClient::CreateAudioDecoder(
return nullptr;
}
std::vector<mojom::SupportedVideoDecoderConfigPtr>
std::vector<SupportedVideoDecoderConfig>
MojoMediaClient::GetSupportedVideoDecoderConfigs() {
return std::vector<mojom::SupportedVideoDecoderConfigPtr>();
return {};
}
std::unique_ptr<VideoDecoder> MojoMediaClient::CreateVideoDecoder(
......
......@@ -15,6 +15,7 @@
#include "media/media_buildflags.h"
#include "media/mojo/interfaces/video_decoder.mojom.h"
#include "media/mojo/services/media_mojo_export.h"
#include "media/video/supported_video_decoder_config.h"
namespace base {
class SingleThreadTaskRunner;
......@@ -55,7 +56,7 @@ class MEDIA_MOJO_EXPORT MojoMediaClient {
virtual std::unique_ptr<AudioDecoder> CreateAudioDecoder(
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
virtual std::vector<mojom::SupportedVideoDecoderConfigPtr>
virtual std::vector<SupportedVideoDecoderConfig>
GetSupportedVideoDecoderConfigs();
virtual std::unique_ptr<VideoDecoder> CreateVideoDecoder(
......
......@@ -35,6 +35,8 @@ source_set("video") {
"jpeg_encode_accelerator.h",
"picture.cc",
"picture.h",
"supported_video_decoder_config.cc",
"supported_video_decoder_config.h",
"trace_util.cc",
"trace_util.h",
"video_decode_accelerator.cc",
......@@ -106,6 +108,7 @@ source_set("unit_tests") {
"h264_parser_unittest.cc",
"h264_poc_unittest.cc",
"half_float_maker_unittest.cc",
"supported_video_decoder_config_unittest.cc",
]
if (enable_hevc_demuxing) {
sources += [ "h265_parser_unittest.cc" ]
......
// Copyright 2019 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 "media/video/supported_video_decoder_config.h"
namespace media {
SupportedVideoDecoderConfig::SupportedVideoDecoderConfig() = default;
SupportedVideoDecoderConfig::SupportedVideoDecoderConfig(
VideoCodecProfile profile_min,
VideoCodecProfile profile_max,
const gfx::Size& coded_size_min,
const gfx::Size& coded_size_max,
bool allow_encrypted,
bool require_encrypted)
: profile_min(profile_min),
profile_max(profile_max),
coded_size_min(coded_size_min),
coded_size_max(coded_size_max),
allow_encrypted(allow_encrypted),
require_encrypted(require_encrypted) {}
SupportedVideoDecoderConfig::~SupportedVideoDecoderConfig() = default;
bool SupportedVideoDecoderConfig::Matches(
const VideoDecoderConfig& config) const {
if (config.profile() < profile_min || config.profile() > profile_max)
return false;
if (config.is_encrypted()) {
if (!allow_encrypted)
return false;
} else {
if (require_encrypted)
return false;
}
if (config.coded_size().width() < coded_size_min.width())
return false;
if (config.coded_size().height() < coded_size_min.height())
return false;
if (config.coded_size().width() > coded_size_max.width())
return false;
if (config.coded_size().height() > coded_size_max.height())
return false;
return true;
}
} // namespace media
// Copyright 2019 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.
#ifndef MEDIA_VIDEO_SUPPORTED_VIDEO_DECODER_CONFIG_H_
#define MEDIA_VIDEO_SUPPORTED_VIDEO_DECODER_CONFIG_H_
#include "base/macros.h"
#include "media/base/media_export.h"
#include "media/base/video_codecs.h"
#include "media/base/video_decoder_config.h"
#include "ui/gfx/geometry/size.h"
namespace media {
// Specification of a range of configurations that are supported by a video
// decoder. Also provides the ability to check if a VideoDecoderConfig matches
// the supported range.
struct MEDIA_EXPORT SupportedVideoDecoderConfig {
SupportedVideoDecoderConfig();
SupportedVideoDecoderConfig(VideoCodecProfile profile_min,
VideoCodecProfile profile_max,
const gfx::Size& coded_size_min,
const gfx::Size& coded_size_max,
bool allow_encrypted,
bool require_encrypted);
~SupportedVideoDecoderConfig();
// Returns true if and only if |config| is a supported config.
bool Matches(const VideoDecoderConfig& config) const;
// Range of VideoCodecProfiles to match, inclusive.
VideoCodecProfile profile_min = VIDEO_CODEC_PROFILE_UNKNOWN;
VideoCodecProfile profile_max = VIDEO_CODEC_PROFILE_UNKNOWN;
// Coded size range, inclusive.
gfx::Size coded_size_min;
gfx::Size coded_size_max;
// TODO(liberato): consider switching these to "allow_clear" and
// "allow_encrypted", so that they're orthogonal.
// If true, then this will match encrypted configs.
bool allow_encrypted = true;
// If true, then unencrypted configs will not match.
bool require_encrypted = false;
// Allow copy and assignment.
};
} // namespace media
#endif // MEDIA_VIDEO_SUPPORTED_VIDEO_DECODER_CONFIG_H_
// Copyright 2019 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 "media/video/supported_video_decoder_config.h"
#include "media/base/test_helpers.h"
#include "media/base/video_codecs.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
class SupportedVideoDecoderConfigTest : public ::testing::Test {
public:
SupportedVideoDecoderConfigTest()
: decoder_config_(
TestVideoConfig::NormalCodecProfile(kCodecH264,
H264PROFILE_EXTENDED)) {
supported_config_.profile_min = H264PROFILE_MIN;
supported_config_.profile_max = H264PROFILE_MAX;
supported_config_.coded_size_min = gfx::Size(10, 20);
supported_config_.coded_size_max = gfx::Size(10000, 20000);
supported_config_.allow_encrypted = true;
supported_config_.require_encrypted = false;
}
SupportedVideoDecoderConfig supported_config_;
// Decoder config that matches |supported_config_|.
VideoDecoderConfig decoder_config_;
};
TEST_F(SupportedVideoDecoderConfigTest, ConstructionWithArgs) {
SupportedVideoDecoderConfig config2(
supported_config_.profile_min, supported_config_.profile_max,
supported_config_.coded_size_min, supported_config_.coded_size_max,
supported_config_.allow_encrypted, supported_config_.require_encrypted);
EXPECT_EQ(supported_config_.profile_min, config2.profile_min);
EXPECT_EQ(supported_config_.profile_max, config2.profile_max);
EXPECT_EQ(supported_config_.coded_size_min, config2.coded_size_min);
EXPECT_EQ(supported_config_.coded_size_max, config2.coded_size_max);
EXPECT_EQ(supported_config_.allow_encrypted, config2.allow_encrypted);
EXPECT_EQ(supported_config_.require_encrypted, config2.require_encrypted);
}
TEST_F(SupportedVideoDecoderConfigTest, MatchingConfigMatches) {
EXPECT_TRUE(supported_config_.Matches(decoder_config_));
// Since |supported_config_| allows encrypted, this should also succeed.
decoder_config_.SetIsEncrypted(true);
EXPECT_TRUE(supported_config_.Matches(decoder_config_));
}
TEST_F(SupportedVideoDecoderConfigTest, LowerProfileMismatches) {
// Raise |profile_min| above |decoder_config_|.
supported_config_.profile_min = H264PROFILE_HIGH;
EXPECT_FALSE(supported_config_.Matches(decoder_config_));
}
TEST_F(SupportedVideoDecoderConfigTest, HigherProfileMismatches) {
// Lower |profile_max| below |decoder_config_|.
supported_config_.profile_max = H264PROFILE_MAIN;
EXPECT_FALSE(supported_config_.Matches(decoder_config_));
}
TEST_F(SupportedVideoDecoderConfigTest, SmallerMinWidthMismatches) {
supported_config_.coded_size_min =
gfx::Size(decoder_config_.coded_size().width() + 1, 0);
EXPECT_FALSE(supported_config_.Matches(decoder_config_));
}
TEST_F(SupportedVideoDecoderConfigTest, SmallerMinHeightMismatches) {
supported_config_.coded_size_min =
gfx::Size(0, decoder_config_.coded_size().height() + 1);
EXPECT_FALSE(supported_config_.Matches(decoder_config_));
}
TEST_F(SupportedVideoDecoderConfigTest, LargerMaxWidthMismatches) {
supported_config_.coded_size_max =
gfx::Size(decoder_config_.coded_size().width() - 1, 10000);
EXPECT_FALSE(supported_config_.Matches(decoder_config_));
}
TEST_F(SupportedVideoDecoderConfigTest, LargerMaxHeightMismatches) {
supported_config_.coded_size_max =
gfx::Size(10000, decoder_config_.coded_size().height() - 1);
EXPECT_FALSE(supported_config_.Matches(decoder_config_));
}
TEST_F(SupportedVideoDecoderConfigTest, RequiredEncryptionMismatches) {
supported_config_.require_encrypted = true;
EXPECT_FALSE(supported_config_.Matches(decoder_config_));
// The encrypted version should succeed.
decoder_config_.SetIsEncrypted(true);
EXPECT_TRUE(supported_config_.Matches(decoder_config_));
}
TEST_F(SupportedVideoDecoderConfigTest, AllowedEncryptionMismatches) {
supported_config_.allow_encrypted = false;
decoder_config_.SetIsEncrypted(true);
EXPECT_FALSE(supported_config_.Matches(decoder_config_));
}
} // namespace media
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment