platform_info_serializer.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2021 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. #ifndef CHROMECAST_SHARED_PLATFORM_INFO_SERIALIZER_H_
  5. #define CHROMECAST_SHARED_PLATFORM_INFO_SERIALIZER_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/strings/string_piece.h"
  9. #include "chromecast/public/media/decoder_config.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. #include "third_party/cast_core/public/src/proto/bindings/media_capabilities.pb.h"
  12. namespace chromecast {
  13. // This class is responsible for serialization and deserialization of JSON
  14. // messages used for specifying the media capabilities of a Cast receiver.
  15. class PlatformInfoSerializer {
  16. public:
  17. // Information about a supported audio codec.
  18. struct AudioCodecInfo {
  19. media::AudioCodec codec = media::AudioCodec::kAudioCodecUnknown;
  20. media::SampleFormat sample_format =
  21. media::SampleFormat::kUnknownSampleFormat;
  22. int max_samples_per_second = 0;
  23. int max_audio_channels = 0;
  24. };
  25. // Information about a supported video codec.
  26. struct VideoCodecInfo {
  27. media::VideoCodec codec = media::VideoCodec::kVideoCodecUnknown;
  28. media::VideoProfile profile = media::VideoProfile::kVideoProfileUnknown;
  29. };
  30. PlatformInfoSerializer();
  31. PlatformInfoSerializer(PlatformInfoSerializer&& other);
  32. ~PlatformInfoSerializer();
  33. PlatformInfoSerializer& operator=(PlatformInfoSerializer&& other);
  34. cast::bindings::MediaCapabilitiesMessage* platform_info();
  35. std::string Serialize() const;
  36. static absl::optional<PlatformInfoSerializer> Deserialize(
  37. base::StringPiece base64);
  38. // Setters for known valid properties.
  39. void SetMaxWidth(int max_width);
  40. void SetMaxHeight(int max_height);
  41. void SetMaxFrameRate(int max_frame_rate);
  42. void SetSupportedCryptoBlockFormat(const std::string& format);
  43. void SetMaxChannels(int max_channels);
  44. void SetPcmSurroundSoundSupported(bool is_supported);
  45. void SetPlatformDolbyVisionEnabled(bool is_enabled);
  46. void SetDolbyVisionSupported(bool is_supported);
  47. void SetDolbyVision4kP60Supported(bool is_supported);
  48. void SetDolbyVisionSupportedByCurrentHdmiMode(bool is_supported);
  49. void SetHdmiVideoModeSwitchEnabled(bool is_enabled);
  50. void SetPlatformHevcEnabled(bool is_enabled);
  51. void SetHdmiModeHdrCheckEnforced(bool is_enforced);
  52. void SetHdrSupportedByCurrentHdmiMode(bool is_supported);
  53. void SetSmpteSt2084Supported(bool is_supported);
  54. void SetHlgSupported(bool is_supported);
  55. void SetHdrFeatureEnabled(bool is_enabled);
  56. void SetHdcpVersion(int hdcp_version);
  57. void SetSpatialRenderingSupportMask(int mask);
  58. void SetMaxFillRate(int max_fill_rate);
  59. void SetSupportedAudioCodecs(std::vector<AudioCodecInfo> codec_infos);
  60. void SetSupportedVideoCodecs(std::vector<VideoCodecInfo> codec_infos);
  61. // Getters for the same properties. Returns absl::nullopt if no such value is
  62. // set, and the set value in all other cases.
  63. absl::optional<int> MaxWidth() const;
  64. absl::optional<int> MaxHeight() const;
  65. absl::optional<int> MaxFrameRate() const;
  66. absl::optional<std::string> SupportedCryptoBlockFormat() const;
  67. absl::optional<int> MaxChannels() const;
  68. absl::optional<bool> PcmSurroundSoundSupported() const;
  69. absl::optional<bool> IsPlatformDolbyVisionEnabled() const;
  70. absl::optional<bool> IsDolbyVisionSupported() const;
  71. absl::optional<bool> IsDolbyVision4kP60Supported() const;
  72. absl::optional<bool> IsDolbyVisionSupportedByCurrentHdmiMode() const;
  73. absl::optional<bool> IsHdmiVideoModeSwitchEnabled() const;
  74. absl::optional<bool> IsPlatformHevcEnabled() const;
  75. absl::optional<bool> IsHdmiModeHdrCheckEnforced() const;
  76. absl::optional<bool> IsHdrSupportedByCurrentHdmiMode() const;
  77. absl::optional<bool> IsSmpteSt2084Supported() const;
  78. absl::optional<bool> IsHlgSupported() const;
  79. absl::optional<bool> IsHdrFeatureEnabled() const;
  80. absl::optional<int> HdcpVersion() const;
  81. absl::optional<int> SpatialRenderingSupportMask() const;
  82. absl::optional<int> MaxFillRate() const;
  83. absl::optional<std::vector<AudioCodecInfo>> SupportedAudioCodecs() const;
  84. absl::optional<std::vector<VideoCodecInfo>> SupportedVideoCodecs() const;
  85. // Deprecated fields.
  86. void SetSupportedLegacyVp9Levels(std::vector<int> levels);
  87. absl::optional<std::vector<int>> SupportedLegacyVp9Levels() const;
  88. private:
  89. // All currently produced values.
  90. cast::bindings::MediaCapabilitiesMessage platform_info_;
  91. };
  92. bool operator==(const PlatformInfoSerializer::AudioCodecInfo& first,
  93. const PlatformInfoSerializer::AudioCodecInfo& second);
  94. bool operator==(const PlatformInfoSerializer::VideoCodecInfo& first,
  95. const PlatformInfoSerializer::VideoCodecInfo& second);
  96. } // namespace chromecast
  97. #endif // CHROMECAST_SHARED_PLATFORM_INFO_SERIALIZER_H_