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.
5 #include "media/remoting/device_capability_checker.h"
7 #include "base/strings/string_util.h"
8 #include "media/base/audio_codecs.h"
9 #include "media/base/video_codecs.h"
11 namespace media::remoting {
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
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);
26 bool IsVideoCodecCompatible(const std::string& model_name,
27 VideoCodec video_codec) {
28 if (!IsKnownToSupportRemoting(model_name)) {
32 if (video_codec == VideoCodec::kH264 || video_codec == VideoCodec::kVP8) {
35 if (model_name == "Chromecast Ultra" &&
36 (video_codec == VideoCodec::kHEVC || video_codec == VideoCodec::kVP9)) {
42 bool IsAudioCodecCompatible(const std::string& model_name,
43 AudioCodec audio_codec) {
44 if (!IsKnownToSupportRemoting(model_name)) {
47 return (audio_codec == AudioCodec::kAAC) ||
48 (audio_codec == AudioCodec::kOpus);
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
55 if (codec_str == "hevc") {
56 return media::VideoCodec::kHEVC;
58 if (codec_str == "h264") {
59 return media::VideoCodec::kH264;
62 return media::StringToVideoCodec(codec_str);
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;
70 return media::AudioCodec::kUnknown;
73 return media::StringToAudioCodec(codec_str);
75 } // namespace media::remoting