OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/media/base/media_codec_support.h" | 5 #include "chromecast/media/base/media_codec_support.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "chromecast/media/base/media_caps.h" | 9 #include "chromecast/media/base/media_caps.h" |
10 #include "chromecast/public/media_codec_support_shlib.h" | 10 #include "chromecast/public/media_codec_support_shlib.h" |
11 | 11 |
12 namespace chromecast { | 12 namespace chromecast { |
13 namespace media { | 13 namespace media { |
14 namespace { | 14 namespace { |
15 | 15 |
16 bool IsCodecSupported(const std::string& codec) { | 16 bool IsCodecSupported(const std::string& codec) { |
17 // FLAC and Opus are supported via the default renderer if the CMA backend | 17 // FLAC and Opus are supported via the default renderer if the CMA backend |
18 // does not have explicit support. | 18 // does not have explicit support. |
19 if (codec == "opus" || codec == "flac") | 19 if (codec == "opus" || codec == "flac") |
20 return true; | 20 return true; |
21 | 21 |
22 MediaCodecSupportShlib::CodecSupport platform_support = | 22 MediaCodecSupportShlib::CodecSupport platform_support = |
23 MediaCodecSupportShlib::IsSupported(codec); | 23 MediaCodecSupportShlib::IsSupported(codec); |
24 if (platform_support == MediaCodecSupportShlib::kSupported) | 24 if (platform_support == MediaCodecSupportShlib::kSupported) |
25 return true; | 25 return true; |
26 else if (platform_support == MediaCodecSupportShlib::kNotSupported) | 26 else if (platform_support == MediaCodecSupportShlib::kNotSupported) |
27 return false; | 27 return false; |
28 | 28 |
| 29 // MediaCodecSupportShlib::IsSupported() returns kDefault. |
29 if (codec == "aac51") { | 30 if (codec == "aac51") { |
30 return MediaCapabilities::HdmiSinkSupportsPcmSurroundSound(); | 31 return MediaCapabilities::HdmiSinkSupportsPcmSurroundSound(); |
31 } | 32 } |
32 if (codec == "ac-3" || codec == "mp4a.a5" || codec == "mp4a.A5") { | 33 if (codec == "ac-3" || codec == "mp4a.a5" || codec == "mp4a.A5") { |
33 return MediaCapabilities::HdmiSinkSupportsAC3(); | 34 return MediaCapabilities::HdmiSinkSupportsAC3(); |
34 } | 35 } |
35 if (codec == "ec-3" || codec == "mp4a.a6" || codec == "mp4a.A6") { | 36 if (codec == "ec-3" || codec == "mp4a.a6" || codec == "mp4a.A6") { |
36 return MediaCapabilities::HdmiSinkSupportsEAC3(); | 37 return MediaCapabilities::HdmiSinkSupportsEAC3(); |
37 } | 38 } |
38 | 39 |
| 40 // For Dolby Vision, getting kDefault from shared library indicates the |
| 41 // platform has external dependency to stream Dolby Vision. It needs to check |
| 42 // HDMI sink capability as well. |
| 43 if (base::StartsWith(codec, "dva1.", base::CompareCase::SENSITIVE) || |
| 44 base::StartsWith(codec, "dvav.", base::CompareCase::SENSITIVE) || |
| 45 base::StartsWith(codec, "dvh1.", base::CompareCase::SENSITIVE) || |
| 46 base::StartsWith(codec, "dvhe.", base::CompareCase::SENSITIVE)) { |
| 47 return MediaCapabilities::HdmiSinkSupportsDolbyVision(); |
| 48 } |
| 49 |
39 // This function is invoked from MimeUtil::AreSupportedCodecs to check if a | 50 // This function is invoked from MimeUtil::AreSupportedCodecs to check if a |
40 // given codec id is supported by Chromecast or not. So by default we should | 51 // given codec id is supported by Chromecast or not. So by default we should |
41 // return true by default to indicate we have no reasons to believe this codec | 52 // return true by default to indicate we have no reasons to believe this codec |
42 // is unsupported. This will allow the rest of MimeUtil checks to proceed as | 53 // is unsupported. This will allow the rest of MimeUtil checks to proceed as |
43 // usual. | 54 // usual. |
44 return true; | 55 return true; |
45 } | 56 } |
46 | 57 |
47 } // namespace | 58 } // namespace |
48 | 59 |
49 ::media::IsCodecSupportedCB GetIsCodecSupportedOnChromecastCB() { | 60 ::media::IsCodecSupportedCB GetIsCodecSupportedOnChromecastCB() { |
50 return base::Bind(&IsCodecSupported); | 61 return base::Bind(&IsCodecSupported); |
51 } | 62 } |
52 | 63 |
53 // Converts ::media::VideoCodec to chromecast::media::VideoCodec. Any unknown or | 64 VideoCodec ToCastVideoCodec(const ::media::VideoCodec video_codec, |
54 // unsupported codec will be converted to chromecast::media::kCodecUnknown. | 65 const ::media::VideoCodecProfile codec_profile) { |
55 VideoCodec ToCastVideoCodec(const ::media::VideoCodec video_codec) { | |
56 switch (video_codec) { | 66 switch (video_codec) { |
57 case ::media::kCodecH264: | 67 case ::media::kCodecH264: |
58 return kCodecH264; | 68 return kCodecH264; |
59 case ::media::kCodecVP8: | 69 case ::media::kCodecVP8: |
60 return kCodecVP8; | 70 return kCodecVP8; |
61 case ::media::kCodecVP9: | 71 case ::media::kCodecVP9: |
62 return kCodecVP9; | 72 return kCodecVP9; |
63 case ::media::kCodecHEVC: | 73 case ::media::kCodecHEVC: |
64 return kCodecHEVC; | 74 return kCodecHEVC; |
| 75 case ::media::kCodecDolbyVision: |
| 76 if (codec_profile == ::media::DOLBYVISION_PROFILE0) { |
| 77 return kCodecDolbyVisionH264; |
| 78 } else if (codec_profile == ::media::DOLBYVISION_PROFILE4 || |
| 79 codec_profile == ::media::DOLBYVISION_PROFILE5 || |
| 80 codec_profile == ::media::DOLBYVISION_PROFILE7) { |
| 81 return kCodecDolbyVisionHEVC; |
| 82 } |
| 83 LOG(ERROR) << "Unsupported video codec profile " << codec_profile; |
| 84 break; |
65 default: | 85 default: |
66 LOG(ERROR) << "Unsupported video codec " << video_codec; | 86 LOG(ERROR) << "Unsupported video codec " << video_codec; |
67 } | 87 } |
68 return kVideoCodecUnknown; | 88 return kVideoCodecUnknown; |
69 } | 89 } |
70 | 90 |
71 // Converts ::media::VideoCodecProfile to chromecast::media::VideoProfile. | |
72 VideoProfile ToCastVideoProfile( | 91 VideoProfile ToCastVideoProfile( |
73 const ::media::VideoCodecProfile codec_profile) { | 92 const ::media::VideoCodecProfile codec_profile) { |
74 switch (codec_profile) { | 93 switch (codec_profile) { |
75 case ::media::H264PROFILE_BASELINE: | 94 case ::media::H264PROFILE_BASELINE: |
76 return kH264Baseline; | 95 return kH264Baseline; |
77 case ::media::H264PROFILE_MAIN: | 96 case ::media::H264PROFILE_MAIN: |
78 return kH264Main; | 97 return kH264Main; |
79 case ::media::H264PROFILE_EXTENDED: | 98 case ::media::H264PROFILE_EXTENDED: |
80 return kH264Extended; | 99 return kH264Extended; |
81 case ::media::H264PROFILE_HIGH: | 100 case ::media::H264PROFILE_HIGH: |
(...skipping 21 matching lines...) Expand all Loading... |
103 case ::media::VP8PROFILE_ANY: | 122 case ::media::VP8PROFILE_ANY: |
104 return kVP8ProfileAny; | 123 return kVP8ProfileAny; |
105 case ::media::VP9PROFILE_PROFILE0: | 124 case ::media::VP9PROFILE_PROFILE0: |
106 return kVP9Profile0; | 125 return kVP9Profile0; |
107 case ::media::VP9PROFILE_PROFILE1: | 126 case ::media::VP9PROFILE_PROFILE1: |
108 return kVP9Profile1; | 127 return kVP9Profile1; |
109 case ::media::VP9PROFILE_PROFILE2: | 128 case ::media::VP9PROFILE_PROFILE2: |
110 return kVP9Profile2; | 129 return kVP9Profile2; |
111 case ::media::VP9PROFILE_PROFILE3: | 130 case ::media::VP9PROFILE_PROFILE3: |
112 return kVP9Profile3; | 131 return kVP9Profile3; |
| 132 case ::media::DOLBYVISION_PROFILE0: |
| 133 return kDolbyVisionCompatible_EL_MD; |
| 134 case ::media::DOLBYVISION_PROFILE4: |
| 135 return kDolbyVisionCompatible_EL_MD; |
| 136 case ::media::DOLBYVISION_PROFILE5: |
| 137 return kDolbyVisionNonCompatible_BL_MD; |
| 138 case ::media::DOLBYVISION_PROFILE7: |
| 139 return kDolbyVisionNonCompatible_BL_EL_MD; |
113 default: | 140 default: |
114 LOG(INFO) << "Unsupported video codec profile " << codec_profile; | 141 LOG(INFO) << "Unsupported video codec profile " << codec_profile; |
115 } | 142 } |
116 return kVideoProfileUnknown; | 143 return kVideoProfileUnknown; |
117 } | 144 } |
118 | 145 |
119 CodecProfileLevel ToCastCodecProfileLevel( | 146 CodecProfileLevel ToCastCodecProfileLevel( |
120 const ::media::CodecProfileLevel& codec_profile_level) { | 147 const ::media::CodecProfileLevel& codec_profile_level) { |
121 CodecProfileLevel result; | 148 CodecProfileLevel result; |
122 result.codec = ToCastVideoCodec(codec_profile_level.codec); | 149 result.codec = |
| 150 ToCastVideoCodec(codec_profile_level.codec, codec_profile_level.profile); |
123 result.profile = ToCastVideoProfile(codec_profile_level.profile); | 151 result.profile = ToCastVideoProfile(codec_profile_level.profile); |
124 result.level = codec_profile_level.level; | 152 result.level = codec_profile_level.level; |
125 return result; | 153 return result; |
126 } | 154 } |
127 | 155 |
128 } // namespace media | 156 } // namespace media |
129 } // namespace chromecast | 157 } // namespace chromecast |
OLD | NEW |