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..01586df9dcec5efb8ba48a10b9955a1bf777f479 |
| --- /dev/null |
| +++ b/content/common/gpu/media/gpu_video_accelerator_util.cc |
| @@ -0,0 +1,120 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
|
wuchengli
2015/03/18 08:02:37
remove (c). http://www.chromium.org/developers/cod
henryhsu
2015/03/18 11:06:08
Done.
|
| +// 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 (size_t i = 0; i < gpu_profiles.size(); i++) { |
| + media::VideoDecodeAccelerator::SupportedProfile profile; |
| + profile.profile = |
| + static_cast<media::VideoCodecProfile>(gpu_profiles[i].profile); |
| + profile.max_resolution = gpu_profiles[i].max_resolution; |
| + profile.min_resolution = gpu_profiles[i].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 (size_t i = 0; i < media_profiles.size(); i++) { |
|
wuchengli
2015/03/18 08:02:37
const auto&. Same for other for loops.
henryhsu
2015/03/18 11:06:09
Done.
|
| + gpu::VideoDecodeAcceleratorSupportedProfile gpu_profile; |
| + gpu_profile.profile = |
| + static_cast<gpu::VideoCodecProfile>(media_profiles[i].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_profiles[i].max_resolution; |
| + gpu_profile.min_resolution = media_profiles[i].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 (size_t i = 0; i < gpu_profiles.size(); i++) { |
| + media::VideoEncodeAccelerator::SupportedProfile profile; |
| + profile.profile = |
| + static_cast<media::VideoCodecProfile>(gpu_profiles[i].profile); |
| + profile.max_resolution = gpu_profiles[i].max_resolution; |
| + profile.max_framerate_numerator = gpu_profiles[i].max_framerate_numerator; |
| + profile.max_framerate_denominator = |
| + gpu_profiles[i].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 (size_t i = 0; i < media_profiles.size(); i++) { |
| + gpu::VideoEncodeAcceleratorSupportedProfile gpu_profile; |
| + gpu_profile.profile = |
| + static_cast<gpu::VideoCodecProfile>(media_profiles[i].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_profiles[i].max_resolution; |
| + gpu_profile.max_framerate_numerator = |
| + media_profiles[i].max_framerate_numerator; |
| + gpu_profile.max_framerate_denominator = |
| + media_profiles[i].max_framerate_denominator; |
| + profiles.push_back(gpu_profile); |
| + } |
| + return profiles; |
| +} |
| + |
| +} // namespace content |