1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_FORMATS_MP4_HEVC_H_
6 #define MEDIA_FORMATS_MP4_HEVC_H_
14 #include "media/base/media_export.h"
15 #include "media/base/video_codecs.h"
16 #include "media/base/video_decoder_config.h"
17 #include "media/formats/mp4/bitstream_converter.h"
18 #include "media/formats/mp4/box_definitions.h"
20 #if BUILDFLAG(IS_TIZEN_TV)
21 #include "third_party/abseil-cpp/absl/types/optional.h"
26 struct SubsampleEntry;
30 struct MEDIA_EXPORT HEVCDecoderConfigurationRecord : Box {
31 DECLARE_BOX_METHODS(HEVCDecoderConfigurationRecord);
33 // Parallel processing tools used by decoder.
35 kMixedParallel = 0, // mixed mode of slice-based/tile-based/wavefront
36 kSliceParallel, // slices can be decoded independently
37 kTileParallel, // tiles can be decoded independently
38 kWaveFrontParallel, // first row of CTUs decoded normally and rest
41 // Parses HEVCDecoderConfigurationRecord data encoded in |data|.
42 // Note: This method is intended to parse data outside the MP4StreamParser
43 // context and therefore the box header is not expected to be present
45 // Returns true if |data| was successfully parsed.
46 bool Parse(const uint8_t* data, int data_size);
47 bool Serialize(std::vector<uint8_t>& output) const;
49 uint8_t configurationVersion;
50 uint8_t general_profile_space;
51 uint8_t general_tier_flag;
52 uint8_t general_profile_idc;
53 uint32_t general_profile_compatibility_flags;
54 uint64_t general_constraint_indicator_flags;
55 uint8_t general_level_idc;
56 uint16_t min_spatial_segmentation_idc;
57 uint8_t parallelismType;
59 uint8_t bitDepthLumaMinus8;
60 uint8_t bitDepthChromaMinus8;
61 uint16_t avgFrameRate;
62 uint8_t constantFrameRate;
63 uint8_t numTemporalLayers;
64 uint8_t temporalIdNested;
65 uint8_t lengthSizeMinusOne;
68 typedef std::vector<uint8_t> HVCCNALUnit;
71 HVCCNALArray(const HVCCNALArray& other);
74 0; // array_completeness(1)/reserved0(1)/NAL_unit_type(6)
75 std::vector<HVCCNALUnit> units;
77 std::vector<HVCCNALArray> arrays;
79 VideoCodecProfile GetVideoProfile() const;
80 #if BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
81 VideoColorSpace GetColorSpace();
82 gfx::HDRMetadata GetHDRMetadata();
83 VideoDecoderConfig::AlphaMode GetAlphaMode();
84 #endif // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
87 bool ParseInternal(BufferReader* reader, MediaLog* media_log);
88 VideoColorSpace color_space;
89 gfx::HDRMetadata hdr_metadata;
90 VideoDecoderConfig::AlphaMode alpha_mode;
93 class MEDIA_EXPORT HEVC {
95 static void ConvertConfigToAnnexB(
96 const HEVCDecoderConfigurationRecord& hevc_config,
97 std::vector<uint8_t>* buffer);
99 static bool InsertParamSetsAnnexB(
100 const HEVCDecoderConfigurationRecord& hevc_config,
101 std::vector<uint8_t>* buffer,
102 std::vector<SubsampleEntry>* subsamples);
104 // Analyzes the contents of |buffer| for conformance to
105 // Section 7.4.2.4.4 of ISO/IEC 23008-2, and if conformant, further inspects
106 // |buffer| to report whether or not it looks like a keyframe.
107 // |subsamples| contains the information about what parts of the buffer are
108 // encrypted and which parts are clear.
109 static BitstreamConverter::AnalysisResult AnalyzeAnnexB(
110 const uint8_t* buffer,
112 const std::vector<SubsampleEntry>& subsamples);
115 class HEVCBitstreamConverter : public BitstreamConverter {
117 explicit HEVCBitstreamConverter(
118 std::unique_ptr<HEVCDecoderConfigurationRecord> hevc_config);
120 // BitstreamConverter interface
121 bool ConvertAndAnalyzeFrame(std::vector<uint8_t>* frame_buf,
123 std::vector<SubsampleEntry>* subsamples,
124 AnalysisResult* analysis_result) const override;
126 #if BUILDFLAG(IS_TIZEN_TV)
127 void SetFramerate(const StreamFramerate::Framerate& framerate) override;
131 ~HEVCBitstreamConverter() override;
132 AnalysisResult Analyze(
133 std::vector<uint8_t>* frame_buf,
134 std::vector<SubsampleEntry>* subsamples) const override;
135 std::unique_ptr<HEVCDecoderConfigurationRecord> hevc_config_;
137 #if BUILDFLAG(IS_TIZEN_TV)
138 absl::optional<StreamFramerate::Framerate> framerate_;
145 #endif // MEDIA_FORMATS_MP4_HEVC_H_