Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / common / gpu / media / gpu_video_accelerator_util.cc
blobd23c19206982131c27a3a324668069fb0d44d501
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/gpu/media/gpu_video_accelerator_util.h"
7 namespace content {
9 // Make sure the enum values of media::VideoCodecProfile and
10 // gpu::VideoCodecProfile match.
11 #define STATIC_ASSERT_ENUM_MATCH(name) \
12 static_assert( \
13 media::name == static_cast<media::VideoCodecProfile>(gpu::name), \
14 #name " value must match in media and gpu.")
16 STATIC_ASSERT_ENUM_MATCH(VIDEO_CODEC_PROFILE_UNKNOWN);
17 STATIC_ASSERT_ENUM_MATCH(VIDEO_CODEC_PROFILE_MIN);
18 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_BASELINE);
19 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_MAIN);
20 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_EXTENDED);
21 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_HIGH);
22 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_HIGH10PROFILE);
23 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_HIGH422PROFILE);
24 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_HIGH444PREDICTIVEPROFILE);
25 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_SCALABLEBASELINE);
26 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_SCALABLEHIGH);
27 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_STEREOHIGH);
28 STATIC_ASSERT_ENUM_MATCH(H264PROFILE_MULTIVIEWHIGH);
29 STATIC_ASSERT_ENUM_MATCH(VP8PROFILE_ANY);
30 STATIC_ASSERT_ENUM_MATCH(VP9PROFILE_ANY);
31 STATIC_ASSERT_ENUM_MATCH(VIDEO_CODEC_PROFILE_MAX);
33 // static
34 media::VideoDecodeAccelerator::SupportedProfiles
35 GpuVideoAcceleratorUtil::ConvertGpuToMediaDecodeProfiles(const
36 gpu::VideoDecodeAcceleratorSupportedProfiles& gpu_profiles) {
37 media::VideoDecodeAccelerator::SupportedProfiles profiles;
38 for (const auto& gpu_profile : gpu_profiles) {
39 media::VideoDecodeAccelerator::SupportedProfile profile;
40 profile.profile =
41 static_cast<media::VideoCodecProfile>(gpu_profile.profile);
42 profile.max_resolution = gpu_profile.max_resolution;
43 profile.min_resolution = gpu_profile.min_resolution;
44 profiles.push_back(profile);
46 return profiles;
49 // static
50 gpu::VideoDecodeAcceleratorSupportedProfiles
51 GpuVideoAcceleratorUtil::ConvertMediaToGpuDecodeProfiles(const
52 media::VideoDecodeAccelerator::SupportedProfiles& media_profiles) {
53 gpu::VideoDecodeAcceleratorSupportedProfiles profiles;
54 for (const auto& media_profile : media_profiles) {
55 gpu::VideoDecodeAcceleratorSupportedProfile profile;
56 profile.profile =
57 static_cast<gpu::VideoCodecProfile>(media_profile.profile);
58 profile.max_resolution = media_profile.max_resolution;
59 profile.min_resolution = media_profile.min_resolution;
60 profiles.push_back(profile);
62 return profiles;
65 // static
66 media::VideoEncodeAccelerator::SupportedProfiles
67 GpuVideoAcceleratorUtil::ConvertGpuToMediaEncodeProfiles(const
68 gpu::VideoEncodeAcceleratorSupportedProfiles& gpu_profiles) {
69 media::VideoEncodeAccelerator::SupportedProfiles profiles;
70 for (const auto& gpu_profile : gpu_profiles) {
71 media::VideoEncodeAccelerator::SupportedProfile profile;
72 profile.profile =
73 static_cast<media::VideoCodecProfile>(gpu_profile.profile);
74 profile.max_resolution = gpu_profile.max_resolution;
75 profile.max_framerate_numerator = gpu_profile.max_framerate_numerator;
76 profile.max_framerate_denominator = gpu_profile.max_framerate_denominator;
77 profiles.push_back(profile);
79 return profiles;
82 // static
83 gpu::VideoEncodeAcceleratorSupportedProfiles
84 GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(const
85 media::VideoEncodeAccelerator::SupportedProfiles& media_profiles) {
86 gpu::VideoEncodeAcceleratorSupportedProfiles profiles;
87 for (const auto& media_profile : media_profiles) {
88 gpu::VideoEncodeAcceleratorSupportedProfile profile;
89 profile.profile =
90 static_cast<gpu::VideoCodecProfile>(media_profile.profile);
91 profile.max_resolution = media_profile.max_resolution;
92 profile.max_framerate_numerator = media_profile.max_framerate_numerator;
93 profile.max_framerate_denominator = media_profile.max_framerate_denominator;
94 profiles.push_back(profile);
96 return profiles;
99 // static
100 void GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(
101 const media::VideoDecodeAccelerator::SupportedProfiles& new_profiles,
102 media::VideoDecodeAccelerator::SupportedProfiles* media_profiles) {
103 for (const auto& profile : new_profiles) {
104 bool duplicate = false;
105 for (const auto& media_profile : *media_profiles) {
106 if (media_profile.profile == profile.profile) {
107 duplicate = true;
108 break;
111 if (!duplicate)
112 media_profiles->push_back(profile);
116 // static
117 void GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles(
118 const media::VideoEncodeAccelerator::SupportedProfiles& new_profiles,
119 media::VideoEncodeAccelerator::SupportedProfiles* media_profiles) {
120 for (const auto& profile : new_profiles) {
121 bool duplicate = false;
122 for (const auto& media_profile : *media_profiles) {
123 if (media_profile.profile == profile.profile) {
124 duplicate = true;
125 break;
128 if (!duplicate)
129 media_profiles->push_back(profile);
133 } // namespace content