Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: media/filters/h265_parser.h

Issue 816353010: Implemented HEVC video demuxing and parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjusted inclusion of hevc source files in gyp/gn Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 //
5 // This file contains an implementation of an H264 Annex-B video stream parser.
6
7 #ifndef MEDIA_FILTERS_H265_PARSER_H_
8 #define MEDIA_FILTERS_H265_PARSER_H_
9
10 #include <sys/types.h>
11
12 #include <map>
13 #include <vector>
14
15 #include "base/basictypes.h"
16 #include "media/base/media_export.h"
17 #include "media/base/ranges.h"
18 #include "media/filters/h264_bit_reader.h"
19 #include "media/filters/h264_parser.h"
20
21 namespace media {
22
23 struct SubsampleEntry;
24
25 // For explanations of each struct and its members, see H.265 specification
26 // at http://www.itu.int/rec/T-REC-H.265.
27 struct MEDIA_EXPORT H265NALU {
28 H265NALU();
29
30 // NAL Unit types are taken from Table 7-1 of HEVC/H265 standard
31 // http://www.itu.int/rec/T-REC-H.265-201410-I/en
32 enum Type {
33 TRAIL_N = 0,
34 TRAIL_R = 1,
35 TSA_N = 2,
36 TSA_R = 3,
37 STSA_N = 4,
38 STSA_R = 5,
39 RADL_N = 6,
40 RADL_R = 7,
41 RASL_N = 8,
42 RASL_R = 9,
43 RSV_VCL_N10 = 10,
44 RSV_VCL_R11 = 11,
45 RSV_VCL_N12 = 12,
46 RSV_VCL_R13 = 13,
47 RSV_VCL_N14 = 14,
48 RSV_VCL_R15 = 15,
49 BLA_W_LP = 16,
50 BLA_W_RADL = 17,
51 BLA_N_LP = 18,
52 IDR_W_RADL = 19,
53 IDR_N_LP = 20,
54 CRA_NUT = 21,
55 RSV_IRAP_VCL22 = 22,
56 RSV_IRAP_VCL23 = 23,
57 RSV_VCL24 = 24,
58 RSV_VCL25 = 25,
59 RSV_VCL26 = 26,
60 RSV_VCL27 = 27,
61 RSV_VCL28 = 28,
62 RSV_VCL29 = 29,
63 RSV_VCL30 = 30,
64 RSV_VCL31 = 31,
65 VPS_NUT = 32,
66 SPS_NUT = 33,
67 PPS_NUT = 34,
68 AUD_NUT = 35,
69 EOS_NUT = 36,
70 EOB_NUT = 37,
71 FD_NUT = 38,
72 PREFIX_SEI_NUT = 39,
73 SUFFIX_SEI_NUT = 40,
74 RSV_NVCL41 = 41,
75 RSV_NVCL42 = 42,
76 RSV_NVCL43 = 43,
77 RSV_NVCL44 = 44,
78 RSV_NVCL45 = 45,
79 RSV_NVCL46 = 46,
80 RSV_NVCL47 = 47,
81 };
82
83 // After (without) start code; we don't own the underlying memory
84 // and a shallow copy should be made when copying this struct.
85 const uint8* data;
86 off_t size; // From after start code to start code of next NALU (or EOS).
87
88 int nal_unit_type;
89 int nuh_layer_id;
90 int nuh_temporal_id_plus1;
91 };
92
93 // Class to parse an Annex-B H.265 stream,
94 class MEDIA_EXPORT H265Parser {
95 public:
96 enum Result {
97 kOk,
98 kInvalidStream, // error in stream
99 kUnsupportedStream, // stream not supported by the parser
100 kEOStream, // end of stream
101 };
102
103 H265Parser();
104 ~H265Parser();
105
106 void Reset();
107 // Set current stream pointer to |stream| of |stream_size| in bytes,
108 // |stream| owned by caller.
109 // |subsamples| contains information about what parts of |stream| are
110 // encrypted.
111 void SetStream(const uint8* stream, off_t stream_size);
112 void SetEncryptedStream(const uint8* stream, off_t stream_size,
113 const std::vector<SubsampleEntry>& subsamples);
114
115 // Read the stream to find the next NALU, identify it and return
116 // that information in |*nalu|. This advances the stream to the beginning
117 // of this NALU, but not past it, so subsequent calls to NALU-specific
118 // parsing functions (ParseSPS, etc.) will parse this NALU.
119 // If the caller wishes to skip the current NALU, it can call this function
120 // again, instead of any NALU-type specific parse functions below.
121 Result AdvanceToNextNALU(H265NALU* nalu);
122
123 private:
124 // Move the stream pointer to the beginning of the next NALU,
125 // i.e. pointing at the next start code.
126 // Return true if a NALU has been found.
127 // If a NALU is found:
128 // - its size in bytes is returned in |*nalu_size| and includes
129 // the start code as well as the trailing zero bits.
130 // - the size in bytes of the start code is returned in |*start_code_size|.
131 bool LocateNALU(off_t* nalu_size, off_t* start_code_size);
132
133 // Pointer to the current NALU in the stream.
134 const uint8* stream_;
135
136 // Bytes left in the stream after the current NALU.
137 off_t bytes_left_;
138
139 H264BitReader br_;
140
141 // Ranges of encrypted bytes in the buffer passed to
142 // SetEncryptedStream().
143 Ranges<const uint8*> encrypted_ranges_;
144
145 DISALLOW_COPY_AND_ASSIGN(H265Parser);
146 };
147
148 } // namespace media
149
150 #endif // MEDIA_FILTERS_H265_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698