| 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 "media/base/video_codecs.h" | 5 #include "media/base/video_codecs.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 case 3: | 146 case 3: |
| 147 *profile = VP9PROFILE_PROFILE3; | 147 *profile = VP9PROFILE_PROFILE3; |
| 148 break; | 148 break; |
| 149 default: | 149 default: |
| 150 DVLOG(3) << __func__ << " Invalid profile (" << profile_idc << ")"; | 150 DVLOG(3) << __func__ << " Invalid profile (" << profile_idc << ")"; |
| 151 return false; | 151 return false; |
| 152 } | 152 } |
| 153 | 153 |
| 154 *level_idc = values[1]; | 154 *level_idc = values[1]; |
| 155 switch (*level_idc) { | 155 switch (*level_idc) { |
| 156 case 1: | 156 case 10: |
| 157 case 11: | 157 case 11: |
| 158 case 2: | 158 case 20: |
| 159 case 21: | 159 case 21: |
| 160 case 3: | 160 case 30: |
| 161 case 31: | 161 case 31: |
| 162 case 4: | 162 case 40: |
| 163 case 41: | 163 case 41: |
| 164 case 5: | 164 case 50: |
| 165 case 51: | 165 case 51: |
| 166 case 52: | 166 case 52: |
| 167 case 6: | 167 case 60: |
| 168 case 61: | 168 case 61: |
| 169 case 62: | 169 case 62: |
| 170 break; | 170 break; |
| 171 default: | 171 default: |
| 172 DVLOG(3) << __func__ << " Invalid level (" << *level_idc << ")"; | 172 DVLOG(3) << __func__ << " Invalid level (" << *level_idc << ")"; |
| 173 return false; | 173 return false; |
| 174 } | 174 } |
| 175 | 175 |
| 176 const int bit_depth = values[2]; | 176 const int bit_depth = values[2]; |
| 177 if (bit_depth != 8 && bit_depth != 10 && bit_depth != 12) { | 177 if (bit_depth != 8 && bit_depth != 10 && bit_depth != 12) { |
| 178 DVLOG(3) << __func__ << " Invalid bit-depth (" << bit_depth << ")"; | 178 DVLOG(3) << __func__ << " Invalid bit-depth (" << bit_depth << ")"; |
| 179 return false; | 179 return false; |
| 180 } | 180 } |
| 181 | 181 |
| 182 if (values.size() < 4) | 182 if (values.size() < 4) |
| 183 return true; | 183 return true; |
| 184 color_space->primaries = VideoColorSpace::GetPrimaryID(values[3]); | 184 const int chroma_subsampling = values[3]; |
| 185 if (color_space->primaries == VideoColorSpace::PrimaryID::INVALID) { | 185 if (chroma_subsampling > 3) { |
| 186 DVLOG(3) << __func__ << " Invalid color primaries (" << values[3] << ")"; | 186 DVLOG(3) << __func__ << " Invalid chroma subsampling (" |
| 187 << chroma_subsampling << ")"; |
| 187 return false; | 188 return false; |
| 188 } | 189 } |
| 189 | 190 |
| 190 if (values.size() < 5) | 191 if (values.size() < 5) |
| 191 return true; | 192 return true; |
| 192 color_space->transfer = VideoColorSpace::GetTransferID(values[4]); | 193 color_space->primaries = VideoColorSpace::GetPrimaryID(values[4]); |
| 193 if (color_space->transfer == VideoColorSpace::TransferID::INVALID) { | 194 if (color_space->primaries == VideoColorSpace::PrimaryID::INVALID) { |
| 194 DVLOG(3) << __func__ << " Invalid transfer function (" << values[4] << ")"; | 195 DVLOG(3) << __func__ << " Invalid color primaries (" << values[4] << ")"; |
| 195 return false; | 196 return false; |
| 196 } | 197 } |
| 197 | 198 |
| 198 if (values.size() < 6) | 199 if (values.size() < 6) |
| 199 return true; | 200 return true; |
| 200 color_space->matrix = VideoColorSpace::GetMatrixID(values[5]); | 201 color_space->transfer = VideoColorSpace::GetTransferID(values[5]); |
| 201 if (color_space->matrix == VideoColorSpace::MatrixID::INVALID) { | 202 if (color_space->transfer == VideoColorSpace::TransferID::INVALID) { |
| 202 DVLOG(3) << __func__ << " Invalid matrix coefficients (" << values[5] | 203 DVLOG(3) << __func__ << " Invalid transfer function (" << values[5] << ")"; |
| 203 << ")"; | |
| 204 return false; | 204 return false; |
| 205 } | 205 } |
| 206 | 206 |
| 207 if (values.size() < 7) | 207 if (values.size() < 7) |
| 208 return true; | 208 return true; |
| 209 const int video_full_range_flag = values[6]; | 209 color_space->matrix = VideoColorSpace::GetMatrixID(values[6]); |
| 210 if (color_space->matrix == VideoColorSpace::MatrixID::INVALID) { |
| 211 DVLOG(3) << __func__ << " Invalid matrix coefficients (" << values[6] |
| 212 << ")"; |
| 213 return false; |
| 214 } |
| 215 if (color_space->matrix == VideoColorSpace::MatrixID::RGB && |
| 216 chroma_subsampling != 3) { |
| 217 DVLOG(3) << __func__ << " Invalid combination of chroma_subsampling (" |
| 218 << ") and matrix coefficients (" << values[6] << ")"; |
| 219 } |
| 220 |
| 221 if (values.size() < 8) |
| 222 return true; |
| 223 const int video_full_range_flag = values[7]; |
| 210 if (video_full_range_flag > 1) { | 224 if (video_full_range_flag > 1) { |
| 211 DVLOG(3) << __func__ << " Invalid full range flag (" | 225 DVLOG(3) << __func__ << " Invalid full range flag (" |
| 212 << video_full_range_flag << ")"; | 226 << video_full_range_flag << ")"; |
| 213 return false; | 227 return false; |
| 214 } | 228 } |
| 215 color_space->range = video_full_range_flag == 1 | 229 color_space->range = video_full_range_flag == 1 |
| 216 ? gfx::ColorSpace::RangeID::FULL | 230 ? gfx::ColorSpace::RangeID::FULL |
| 217 : gfx::ColorSpace::RangeID::LIMITED; | 231 : gfx::ColorSpace::RangeID::LIMITED; |
| 218 | 232 |
| 219 if (values.size() < 8) | |
| 220 return true; | |
| 221 const int chroma_subsampling = values[7]; | |
| 222 if (chroma_subsampling > 3 || | |
| 223 (chroma_subsampling != 3 && | |
| 224 color_space->matrix == VideoColorSpace::MatrixID::RGB)) { | |
| 225 DVLOG(3) << __func__ << " Invalid chroma subsampling (" | |
| 226 << chroma_subsampling << ")"; | |
| 227 return false; | |
| 228 } | |
| 229 | |
| 230 return true; | 233 return true; |
| 231 } | 234 } |
| 232 | 235 |
| 233 bool ParseLegacyVp9CodecID(const std::string& codec_id, | 236 bool ParseLegacyVp9CodecID(const std::string& codec_id, |
| 234 VideoCodecProfile* profile, | 237 VideoCodecProfile* profile, |
| 235 uint8_t* level_idc) { | 238 uint8_t* level_idc) { |
| 236 if (codec_id == "vp9" || codec_id == "vp9.0") { | 239 if (codec_id == "vp9" || codec_id == "vp9.0") { |
| 237 // Profile is not included in the codec string. Assuming profile 0 to be | 240 // Profile is not included in the codec string. Assuming profile 0 to be |
| 238 // backward compatible. | 241 // backward compatible. |
| 239 *profile = VP9PROFILE_PROFILE0; | 242 *profile = VP9PROFILE_PROFILE0; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 return kCodecHEVC; | 624 return kCodecHEVC; |
| 622 #endif | 625 #endif |
| 623 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) | 626 #if BUILDFLAG(ENABLE_DOLBY_VISION_DEMUXING) |
| 624 if (ParseDolbyVisionCodecId(codec_id, &profile, &level)) | 627 if (ParseDolbyVisionCodecId(codec_id, &profile, &level)) |
| 625 return kCodecDolbyVision; | 628 return kCodecDolbyVision; |
| 626 #endif | 629 #endif |
| 627 return kUnknownVideoCodec; | 630 return kUnknownVideoCodec; |
| 628 } | 631 } |
| 629 | 632 |
| 630 } // namespace media | 633 } // namespace media |
| OLD | NEW |