media_types.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "media/base/media_types.h"
  5. #include <tuple>
  6. namespace media {
  7. // static
  8. AudioType AudioType::FromDecoderConfig(const AudioDecoderConfig& config) {
  9. return {config.codec(), AudioCodecProfile::kUnknown, false};
  10. }
  11. // static
  12. VideoType VideoType::FromDecoderConfig(const VideoDecoderConfig& config) {
  13. // Level is not part of |config|. Its also not always known in the container
  14. // metadata (e.g. WebM puts it in CodecPrivate which is often not included).
  15. // Level is not used by /media to make/break support decisions, but
  16. // embedders with strict hardware limitations could theoretically check it.
  17. // The following attempts to make a safe guess by choosing the lowest level
  18. // for the given codec.
  19. // Zero is not a valid level for any of the following codecs. It means
  20. // "unknown" or "no level" (e.g. VP8).
  21. int level = 0;
  22. switch (config.codec()) {
  23. // These have no notion of level.
  24. case VideoCodec::kUnknown:
  25. case VideoCodec::kTheora:
  26. case VideoCodec::kVP8:
  27. // These use non-numeric levels, aren't part of our mime code, and
  28. // are ancient with very limited support.
  29. case VideoCodec::kVC1:
  30. case VideoCodec::kMPEG2:
  31. case VideoCodec::kMPEG4:
  32. break;
  33. case VideoCodec::kH264:
  34. case VideoCodec::kVP9:
  35. case VideoCodec::kHEVC:
  36. // 10 is the level_idc for level 1.0.
  37. level = 10;
  38. break;
  39. case VideoCodec::kDolbyVision:
  40. // Dolby doesn't do decimals, so 1 is just 1.
  41. level = 1;
  42. break;
  43. case VideoCodec::kAV1:
  44. // Strangely, AV1 starts at 2.0.
  45. level = 20;
  46. break;
  47. }
  48. return {config.codec(), config.profile(), level, config.color_space_info()};
  49. }
  50. bool operator==(const AudioType& x, const AudioType& y) {
  51. return std::tie(x.codec, x.profile, x.spatial_rendering) ==
  52. std::tie(y.codec, y.profile, y.spatial_rendering);
  53. }
  54. bool operator!=(const AudioType& x, const AudioType& y) {
  55. return !(x == y);
  56. }
  57. bool operator==(const VideoType& x, const VideoType& y) {
  58. return std::tie(x.codec, x.profile, x.level, x.color_space) ==
  59. std::tie(y.codec, y.profile, y.level, y.color_space);
  60. }
  61. bool operator!=(const VideoType& x, const VideoType& y) {
  62. return !(x == y);
  63. }
  64. } // namespace media