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 // This file contains an implementation of an H265 Annex-B video stream parser.
7 #ifndef MEDIA_FILTERS_H265_PARSER_H_
8 #define MEDIA_FILTERS_H265_PARSER_H_
10 #include <sys/types.h>
15 #include "base/basictypes.h"
16 #include "base/macros.h"
17 #include "media/base/media_export.h"
18 #include "media/base/ranges.h"
19 #include "media/filters/h264_bit_reader.h"
20 #include "media/filters/h264_parser.h"
24 struct SubsampleEntry
;
26 // For explanations of each struct and its members, see H.265 specification
27 // at http://www.itu.int/rec/T-REC-H.265.
28 struct MEDIA_EXPORT H265NALU
{
31 // NAL Unit types are taken from Table 7-1 of HEVC/H265 standard
32 // http://www.itu.int/rec/T-REC-H.265-201410-I/en
84 // After (without) start code; we don't own the underlying memory
85 // and a shallow copy should be made when copying this struct.
87 off_t size
; // From after start code to start code of next NALU (or EOS).
91 int nuh_temporal_id_plus1
;
94 // Class to parse an Annex-B H.265 stream.
95 class MEDIA_EXPORT H265Parser
{
99 kInvalidStream
, // error in stream
100 kUnsupportedStream
, // stream not supported by the parser
101 kEOStream
, // end of stream
108 // Set current stream pointer to |stream| of |stream_size| in bytes,
109 // |stream| owned by caller.
110 // |subsamples| contains information about what parts of |stream| are
112 void SetStream(const uint8
* stream
, off_t stream_size
);
113 void SetEncryptedStream(const uint8
* stream
, off_t stream_size
,
114 const std::vector
<SubsampleEntry
>& subsamples
);
116 // Read the stream to find the next NALU, identify it and return
117 // that information in |*nalu|. This advances the stream to the beginning
118 // of this NALU, but not past it, so subsequent calls to NALU-specific
119 // parsing functions (ParseSPS, etc.) will parse this NALU.
120 // If the caller wishes to skip the current NALU, it can call this function
121 // again, instead of any NALU-type specific parse functions below.
122 Result
AdvanceToNextNALU(H265NALU
* nalu
);
125 // Move the stream pointer to the beginning of the next NALU,
126 // i.e. pointing at the next start code.
127 // Return true if a NALU has been found.
128 // If a NALU is found:
129 // - its size in bytes is returned in |*nalu_size| and includes
130 // the start code as well as the trailing zero bits.
131 // - the size in bytes of the start code is returned in |*start_code_size|.
132 bool LocateNALU(off_t
* nalu_size
, off_t
* start_code_size
);
134 // Pointer to the current NALU in the stream.
135 const uint8
* stream_
;
137 // Bytes left in the stream after the current NALU.
142 // Ranges of encrypted bytes in the buffer passed to
143 // SetEncryptedStream().
144 Ranges
<const uint8
*> encrypted_ranges_
;
146 DISALLOW_COPY_AND_ASSIGN(H265Parser
);
151 #endif // MEDIA_FILTERS_H265_PARSER_H_