[M120 Migration][MM] Framerate calculation
[platform/framework/web/chromium-efl.git] / media / mojo / mojom / cdm_capability_mojom_traits.cc
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/mojo/mojom/cdm_capability_mojom_traits.h"
6
7 #include <set>
8 #include <utility>
9
10 namespace mojo {
11
12 namespace {
13
14 template <typename T>
15 bool AreUnique(const std::vector<T>& values) {
16   std::set<T> unique_values;
17   for (const auto& value : values)
18     unique_values.emplace(value);
19   return values.size() == unique_values.size();
20 }
21
22 }  // namespace
23
24 // static
25 bool StructTraits<media::mojom::VideoCodecInfoDataView, media::VideoCodecInfo>::
26     Read(media::mojom::VideoCodecInfoDataView input,
27          media::VideoCodecInfo* output) {
28   std::vector<media::VideoCodecProfile> supported_profiles;
29   if (!input.ReadSupportedProfiles(&supported_profiles)) {
30     return false;
31   }
32
33   *output = media::VideoCodecInfo(std::move(supported_profiles),
34                                   input.supports_clear_lead());
35   return true;
36 }
37
38 // static
39 bool StructTraits<media::mojom::CdmCapabilityDataView, media::CdmCapability>::
40     Read(media::mojom::CdmCapabilityDataView input,
41          media::CdmCapability* output) {
42   std::vector<media::AudioCodec> audio_codecs;
43   if (!input.ReadAudioCodecs(&audio_codecs))
44     return false;
45
46   media::CdmCapability::VideoCodecMap video_codecs;
47   if (!input.ReadVideoCodecs(&video_codecs))
48     return false;
49
50   std::vector<media::EncryptionScheme> encryption_schemes;
51   if (!input.ReadEncryptionSchemes(&encryption_schemes))
52     return false;
53
54   std::vector<media::CdmSessionType> session_types;
55   if (!input.ReadSessionTypes(&session_types))
56     return false;
57
58   // |encryption_schemes|, |session_types| and |audio_codecs| are converted
59   // to a base::flat_map implicitly.
60   *output = media::CdmCapability(
61       std::move(audio_codecs), std::move(video_codecs),
62       std::move(encryption_schemes), std::move(session_types));
63   return true;
64 }
65
66 }  // namespace mojo