Chromium Code Reviews| Index: content/common/gpu/media/gpu_video_accelerator_util.cc |
| diff --git a/content/common/gpu/media/gpu_video_accelerator_util.cc b/content/common/gpu/media/gpu_video_accelerator_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1b266f313ca2e99572b688ce5adef36f6d76f7d1 |
| --- /dev/null |
| +++ b/content/common/gpu/media/gpu_video_accelerator_util.cc |
| @@ -0,0 +1,118 @@ |
| +// Copyright 2015 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 "content/common/gpu/media/gpu_video_accelerator_util.h" |
| + |
| +namespace content { |
| + |
| +// Make sure the enum values of media::VideoCodecProfile and |
| +// gpu::VideoCodecProfile match. |
| +#define STATIC_ASSERT_ENUM_MATCH(name) \ |
| + static_assert( \ |
| + media::name == static_cast<media::VideoCodecProfile>(gpu::name), \ |
| + #name " value must match in media and gpu.") |
| + |
| +STATIC_ASSERT_ENUM_MATCH(VIDEO_CODEC_PROFILE_UNKNOWN); |
| +STATIC_ASSERT_ENUM_MATCH(VIDEO_CODEC_PROFILE_MIN); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_BASELINE); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_MAIN); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_EXTENDED); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_HIGH); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_HIGH10PROFILE); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_HIGH422PROFILE); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_HIGH444PREDICTIVEPROFILE); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_SCALABLEBASELINE); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_SCALABLEHIGH); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_STEREOHIGH); |
| +STATIC_ASSERT_ENUM_MATCH(H264PROFILE_MULTIVIEWHIGH); |
| +STATIC_ASSERT_ENUM_MATCH(VP8PROFILE_ANY); |
| +STATIC_ASSERT_ENUM_MATCH(VP9PROFILE_ANY); |
| +STATIC_ASSERT_ENUM_MATCH(VIDEO_CODEC_PROFILE_MAX); |
| + |
| +// static |
| +std::vector<media::VideoDecodeAccelerator::SupportedProfile> |
| +GpuVideoAcceleratorUtil::ConvertGpuToMediaDecodeProfiles(const std::vector< |
| + gpu::VideoDecodeAcceleratorSupportedProfile>& gpu_profiles) { |
| + std::vector<media::VideoDecodeAccelerator::SupportedProfile> profiles; |
| + for (const auto& gpu_profile : gpu_profiles) { |
| + media::VideoDecodeAccelerator::SupportedProfile profile; |
| + profile.profile = |
| + static_cast<media::VideoCodecProfile>(gpu_profile.profile); |
| + profile.max_resolution = gpu_profile.max_resolution; |
| + profile.min_resolution = gpu_profile.min_resolution; |
| + profiles.push_back(profile); |
| + } |
| + return profiles; |
| +} |
| + |
| +// static |
| +std::vector<gpu::VideoDecodeAcceleratorSupportedProfile> |
| +GpuVideoAcceleratorUtil::ConvertMediaToGpuDecodeProfiles(const std::vector< |
| + media::VideoDecodeAccelerator::SupportedProfile>& media_profiles) { |
| + std::vector<gpu::VideoDecodeAcceleratorSupportedProfile> profiles; |
| + for (const auto& media_profile : media_profiles) { |
| + gpu::VideoDecodeAcceleratorSupportedProfile gpu_profile; |
| + gpu_profile.profile = |
| + static_cast<gpu::VideoCodecProfile>(media_profile.profile); |
| + bool duplicate = false; |
| + for (const auto& profile : profiles) { |
| + if (profile.profile == gpu_profile.profile) { |
| + duplicate = true; |
|
wuchengli
2015/03/19 06:19:24
I prefer moving out the logic of removing duplicat
henryhsu
2015/03/19 10:00:32
Done.
|
| + break; |
| + } |
| + } |
| + if (duplicate) |
| + continue; |
| + gpu_profile.max_resolution = media_profile.max_resolution; |
| + gpu_profile.min_resolution = media_profile.min_resolution; |
| + profiles.push_back(gpu_profile); |
| + } |
| + return profiles; |
| +} |
| + |
| +// static |
| +std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
| +GpuVideoAcceleratorUtil::ConvertGpuToMediaEncodeProfiles(const std::vector< |
| + gpu::VideoEncodeAcceleratorSupportedProfile>& gpu_profiles) { |
| + std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles; |
| + for (const auto& gpu_profile : gpu_profiles) { |
| + media::VideoEncodeAccelerator::SupportedProfile profile; |
| + profile.profile = |
| + static_cast<media::VideoCodecProfile>(gpu_profile.profile); |
| + profile.max_resolution = gpu_profile.max_resolution; |
| + profile.max_framerate_numerator = gpu_profile.max_framerate_numerator; |
| + profile.max_framerate_denominator = gpu_profile.max_framerate_denominator; |
| + profiles.push_back(profile); |
| + } |
| + return profiles; |
| +} |
| + |
| +// static |
| +std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> |
| +GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(const std::vector< |
| + media::VideoEncodeAccelerator::SupportedProfile>& media_profiles) { |
| + std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> profiles; |
| + for (const auto& media_profile : media_profiles) { |
| + gpu::VideoEncodeAcceleratorSupportedProfile gpu_profile; |
| + gpu_profile.profile = |
| + static_cast<gpu::VideoCodecProfile>(media_profile.profile); |
| + bool duplicate = false; |
| + for (const auto& profile : profiles) { |
| + if (profile.profile == gpu_profile.profile) { |
| + duplicate = true; |
| + break; |
| + } |
| + } |
| + if (duplicate) |
| + continue; |
| + gpu_profile.max_resolution = media_profile.max_resolution; |
| + gpu_profile.max_framerate_numerator = media_profile.max_framerate_numerator; |
| + gpu_profile.max_framerate_denominator = |
| + media_profile.max_framerate_denominator; |
| + profiles.push_back(gpu_profile); |
| + } |
| + return profiles; |
| +} |
| + |
| +} // namespace content |