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.
5 #ifndef MEDIA_FORMATS_MP4_HEVC_H_
6 #define MEDIA_FORMATS_MP4_HEVC_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "media/base/media_export.h"
13 #include "media/formats/mp4/bitstream_converter.h"
14 #include "media/formats/mp4/box_definitions.h"
18 struct SubsampleEntry
;
22 struct MEDIA_EXPORT HEVCDecoderConfigurationRecord
: Box
{
23 DECLARE_BOX_METHODS(HEVCDecoderConfigurationRecord
);
25 // Parses HEVCDecoderConfigurationRecord data encoded in |data|.
26 // Note: This method is intended to parse data outside the MP4StreamParser
27 // context and therefore the box header is not expected to be present
29 // Returns true if |data| was successfully parsed.
30 bool Parse(const uint8
* data
, int data_size
);
32 uint8 configurationVersion
;
33 uint8 general_profile_space
;
34 uint8 general_tier_flag
;
35 uint8 general_profile_idc
;
36 uint32 general_profile_compatibility_flags
;
37 uint64 general_constraint_indicator_flags
;
38 uint8 general_level_idc
;
39 uint16 min_spatial_segmentation_idc
;
40 uint8 parallelismType
;
42 uint8 bitDepthLumaMinus8
;
43 uint8 bitDepthChromaMinus8
;
45 uint8 constantFrameRate
;
46 uint8 numTemporalLayers
;
47 uint8 temporalIdNested
;
48 uint8 lengthSizeMinusOne
;
51 typedef std::vector
<uint8
> HVCCNALUnit
;
56 std::vector
<HVCCNALUnit
> units
;
58 std::vector
<HVCCNALArray
> arrays
;
61 bool ParseInternal(BufferReader
* reader
,
62 const scoped_refptr
<MediaLog
>& media_log
);
65 class MEDIA_EXPORT HEVC
{
67 static bool ConvertConfigToAnnexB(
68 const HEVCDecoderConfigurationRecord
& hevc_config
,
69 std::vector
<uint8
>* buffer
);
71 static bool InsertParamSetsAnnexB(
72 const HEVCDecoderConfigurationRecord
& hevc_config
,
73 std::vector
<uint8
>* buffer
,
74 std::vector
<SubsampleEntry
>* subsamples
);
76 // Verifies that the contents of |buffer| conform to
77 // Section 7.4.2.4.4 of ISO/IEC 23008-2.
78 // |subsamples| contains the information about what parts of the buffer are
79 // encrypted and which parts are clear.
80 // Returns true if |buffer| contains conformant Annex B data
81 // TODO(servolk): Remove the std::vector version when we can use,
82 // C++11's std::vector<T>::data() method.
83 static bool IsValidAnnexB(const std::vector
<uint8
>& buffer
,
84 const std::vector
<SubsampleEntry
>& subsamples
);
85 static bool IsValidAnnexB(const uint8
* buffer
, size_t size
,
86 const std::vector
<SubsampleEntry
>& subsamples
);
89 class HEVCBitstreamConverter
: public BitstreamConverter
{
91 explicit HEVCBitstreamConverter(
92 scoped_ptr
<HEVCDecoderConfigurationRecord
> hevc_config
);
94 // BitstreamConverter interface
95 bool ConvertFrame(std::vector
<uint8
>* frame_buf
,
97 std::vector
<SubsampleEntry
>* subsamples
) const override
;
99 ~HEVCBitstreamConverter() override
;
100 scoped_ptr
<HEVCDecoderConfigurationRecord
> hevc_config_
;
106 #endif // MEDIA_FORMATS_MP4_HEVC_H_