hevc.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_FORMATS_MP4_HEVC_H_
  5. #define MEDIA_FORMATS_MP4_HEVC_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <memory>
  9. #include <vector>
  10. #include "media/base/media_export.h"
  11. #include "media/base/video_codecs.h"
  12. #include "media/formats/mp4/bitstream_converter.h"
  13. #include "media/formats/mp4/box_definitions.h"
  14. namespace media {
  15. struct SubsampleEntry;
  16. namespace mp4 {
  17. struct MEDIA_EXPORT HEVCDecoderConfigurationRecord : Box {
  18. DECLARE_BOX_METHODS(HEVCDecoderConfigurationRecord);
  19. // Parses HEVCDecoderConfigurationRecord data encoded in |data|.
  20. // Note: This method is intended to parse data outside the MP4StreamParser
  21. // context and therefore the box header is not expected to be present
  22. // in |data|.
  23. // Returns true if |data| was successfully parsed.
  24. bool Parse(const uint8_t* data, int data_size);
  25. uint8_t configurationVersion;
  26. uint8_t general_profile_space;
  27. uint8_t general_tier_flag;
  28. uint8_t general_profile_idc;
  29. uint32_t general_profile_compatibility_flags;
  30. uint64_t general_constraint_indicator_flags;
  31. uint8_t general_level_idc;
  32. uint16_t min_spatial_segmentation_idc;
  33. uint8_t parallelismType;
  34. uint8_t chromaFormat;
  35. uint8_t bitDepthLumaMinus8;
  36. uint8_t bitDepthChromaMinus8;
  37. uint16_t avgFrameRate;
  38. uint8_t constantFrameRate;
  39. uint8_t numTemporalLayers;
  40. uint8_t temporalIdNested;
  41. uint8_t lengthSizeMinusOne;
  42. uint8_t numOfArrays;
  43. typedef std::vector<uint8_t> HVCCNALUnit;
  44. struct HVCCNALArray {
  45. HVCCNALArray();
  46. HVCCNALArray(const HVCCNALArray& other);
  47. ~HVCCNALArray();
  48. uint8_t first_byte;
  49. std::vector<HVCCNALUnit> units;
  50. };
  51. std::vector<HVCCNALArray> arrays;
  52. VideoCodecProfile GetVideoProfile() const;
  53. #if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
  54. VideoColorSpace GetColorSpace();
  55. #endif // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
  56. private:
  57. bool ParseInternal(BufferReader* reader, MediaLog* media_log);
  58. };
  59. class MEDIA_EXPORT HEVC {
  60. public:
  61. static bool ConvertConfigToAnnexB(
  62. const HEVCDecoderConfigurationRecord& hevc_config,
  63. std::vector<uint8_t>* buffer);
  64. static bool InsertParamSetsAnnexB(
  65. const HEVCDecoderConfigurationRecord& hevc_config,
  66. std::vector<uint8_t>* buffer,
  67. std::vector<SubsampleEntry>* subsamples);
  68. // Analyzes the contents of |buffer| for conformance to
  69. // Section 7.4.2.4.4 of ISO/IEC 23008-2, and if conformant, further inspects
  70. // |buffer| to report whether or not it looks like a keyframe.
  71. // |subsamples| contains the information about what parts of the buffer are
  72. // encrypted and which parts are clear.
  73. static BitstreamConverter::AnalysisResult AnalyzeAnnexB(
  74. const uint8_t* buffer,
  75. size_t size,
  76. const std::vector<SubsampleEntry>& subsamples);
  77. };
  78. class HEVCBitstreamConverter : public BitstreamConverter {
  79. public:
  80. explicit HEVCBitstreamConverter(
  81. std::unique_ptr<HEVCDecoderConfigurationRecord> hevc_config);
  82. // BitstreamConverter interface
  83. bool ConvertAndAnalyzeFrame(std::vector<uint8_t>* frame_buf,
  84. bool is_keyframe,
  85. std::vector<SubsampleEntry>* subsamples,
  86. AnalysisResult* analysis_result) const override;
  87. private:
  88. ~HEVCBitstreamConverter() override;
  89. AnalysisResult Analyze(
  90. std::vector<uint8_t>* frame_buf,
  91. std::vector<SubsampleEntry>* subsamples) const override;
  92. std::unique_ptr<HEVCDecoderConfigurationRecord> hevc_config_;
  93. };
  94. } // namespace mp4
  95. } // namespace media
  96. #endif // MEDIA_FORMATS_MP4_HEVC_H_