Fix FullScreen crash in Webapp
[platform/framework/web/chromium-efl.git] / media / remoting / device_capability_checker.cc
1 // Copyright 2022 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/remoting/device_capability_checker.h"
6
7 #include "base/strings/string_util.h"
8 #include "media/base/audio_codecs.h"
9 #include "media/base/video_codecs.h"
10
11 namespace media::remoting {
12
13 bool IsKnownToSupportRemoting(const std::string& model_name) {
14   // This is a workaround to allowlist certain devices known to support
15   // remoting, so that we can only show media sinks that are known to work for
16   // remote playback.
17   //
18   // TODO(crbug.com/1380864): Use a better mechanism to feature detect remoting
19   // support before mirroring begins.
20   return base::StartsWith(model_name, "Chromecast",
21                           base::CompareCase::SENSITIVE) ||
22          base::StartsWith(model_name, "Eureka Dongle",
23                           base::CompareCase::SENSITIVE);
24 }
25
26 bool IsVideoCodecCompatible(const std::string& model_name,
27                             VideoCodec video_codec) {
28   if (!IsKnownToSupportRemoting(model_name)) {
29     return false;
30   }
31
32   if (video_codec == VideoCodec::kH264 || video_codec == VideoCodec::kVP8) {
33     return true;
34   }
35   if (model_name == "Chromecast Ultra" &&
36       (video_codec == VideoCodec::kHEVC || video_codec == VideoCodec::kVP9)) {
37     return true;
38   }
39   return false;
40 }
41
42 bool IsAudioCodecCompatible(const std::string& model_name,
43                             AudioCodec audio_codec) {
44   if (!IsKnownToSupportRemoting(model_name)) {
45     return false;
46   }
47   return (audio_codec == AudioCodec::kAAC) ||
48          (audio_codec == AudioCodec::kOpus);
49 }
50
51 media::VideoCodec ParseVideoCodec(const std::string& codec_str) {
52 #if BUILDFLAG(USE_PROPRIETARY_CODECS)
53   // `StringToVideoCodec()` does not parse custom strings like "hevc" and
54   // "h264".
55   if (codec_str == "hevc") {
56     return media::VideoCodec::kHEVC;
57   }
58   if (codec_str == "h264") {
59     return media::VideoCodec::kH264;
60   }
61 #endif
62   return media::StringToVideoCodec(codec_str);
63 }
64
65 media::AudioCodec ParseAudioCodec(const std::string& codec_str) {
66   if (codec_str == "aac") {
67 #if BUILDFLAG(USE_PROPRIETARY_CODECS)
68     return media::AudioCodec::kAAC;
69 #else
70     return media::AudioCodec::kUnknown;
71 #endif
72   }
73   return media::StringToAudioCodec(codec_str);
74 }
75 }  // namespace media::remoting