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

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

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // This file contains an implementation of a H264BitstreamBuffer class for 5 // This file contains an implementation of a H264BitstreamBuffer class for
6 // constructing raw bitstream buffers containing NAL units in 6 // constructing raw bitstream buffers containing NAL units in
7 // H.264 Annex-B stream format. 7 // H.264 Annex-B stream format.
8 // See H.264 spec Annex B and chapter 7for more details. 8 // See H.264 spec Annex B and chapter 7for more details.
9 9
10 #ifndef MEDIA_FILTERS_H264_BITSTREAM_BUFFER_H_ 10 #ifndef MEDIA_FILTERS_H264_BITSTREAM_BUFFER_H_
(...skipping 15 matching lines...) Expand all
26 H264BitstreamBuffer(); 26 H264BitstreamBuffer();
27 ~H264BitstreamBuffer(); 27 ~H264BitstreamBuffer();
28 28
29 // Discard all data and reset the buffer for reuse. 29 // Discard all data and reset the buffer for reuse.
30 void Reset(); 30 void Reset();
31 31
32 // Append |num_bits| bits to the stream from |val|. 32 // Append |num_bits| bits to the stream from |val|.
33 // |val| is interpreted in the host endianness. 33 // |val| is interpreted in the host endianness.
34 template <typename T> 34 template <typename T>
35 void AppendBits(size_t num_bits, T val) { 35 void AppendBits(size_t num_bits, T val) {
36 AppendU64(num_bits, static_cast<uint64>(val)); 36 AppendU64(num_bits, static_cast<uint64_t>(val));
37 } 37 }
38 38
39 void AppendBits(size_t num_bits, bool val) { 39 void AppendBits(size_t num_bits, bool val) {
40 DCHECK_EQ(num_bits, 1ul); 40 DCHECK_EQ(num_bits, 1ul);
41 AppendBool(val); 41 AppendBool(val);
42 } 42 }
43 43
44 // Append a one-bit bool/flag value |val| to the stream. 44 // Append a one-bit bool/flag value |val| to the stream.
45 void AppendBool(bool val); 45 void AppendBool(bool val);
46 46
(...skipping 14 matching lines...) Expand all
61 // returned by data() to be correct. 61 // returned by data() to be correct.
62 void FinishNALU(); 62 void FinishNALU();
63 63
64 // Return number of full bytes in the stream. Note that FinishNALU() has to 64 // Return number of full bytes in the stream. Note that FinishNALU() has to
65 // be called to flush cached bits, or the return value will not include them. 65 // be called to flush cached bits, or the return value will not include them.
66 size_t BytesInBuffer(); 66 size_t BytesInBuffer();
67 67
68 // Return a pointer to the stream. FinishNALU() must be called before 68 // Return a pointer to the stream. FinishNALU() must be called before
69 // accessing the stream, otherwise some bits may still be cached and not 69 // accessing the stream, otherwise some bits may still be cached and not
70 // in the buffer. 70 // in the buffer.
71 uint8* data(); 71 uint8_t* data();
72 72
73 private: 73 private:
74 FRIEND_TEST_ALL_PREFIXES(H264BitstreamBufferAppendBitsTest, 74 FRIEND_TEST_ALL_PREFIXES(H264BitstreamBufferAppendBitsTest,
75 AppendAndVerifyBits); 75 AppendAndVerifyBits);
76 76
77 // Allocate additional memory (kGrowBytes bytes) for the buffer. 77 // Allocate additional memory (kGrowBytes bytes) for the buffer.
78 void Grow(); 78 void Grow();
79 79
80 // Append |num_bits| bits from U64 value |val| (in host endianness). 80 // Append |num_bits| bits from U64 value |val| (in host endianness).
81 void AppendU64(size_t num_bits, uint64 val); 81 void AppendU64(size_t num_bits, uint64_t val);
82 82
83 // Flush any cached bits in the reg with byte granularity, i.e. enough 83 // Flush any cached bits in the reg with byte granularity, i.e. enough
84 // bytes to flush all pending bits, but not more. 84 // bytes to flush all pending bits, but not more.
85 void FlushReg(); 85 void FlushReg();
86 86
87 typedef uint64 RegType; 87 typedef uint64_t RegType;
88 enum { 88 enum {
89 // Sizes of reg_. 89 // Sizes of reg_.
90 kRegByteSize = sizeof(RegType), 90 kRegByteSize = sizeof(RegType),
91 kRegBitSize = kRegByteSize * 8, 91 kRegBitSize = kRegByteSize * 8,
92 // Amount of bytes to grow the buffer by when we run out of 92 // Amount of bytes to grow the buffer by when we run out of
93 // previously-allocated memory for it. 93 // previously-allocated memory for it.
94 kGrowBytes = 4096, 94 kGrowBytes = 4096,
95 }; 95 };
96 96
97 static_assert(kGrowBytes >= kRegByteSize, 97 static_assert(kGrowBytes >= kRegByteSize,
98 "kGrowBytes must be larger than kRegByteSize"); 98 "kGrowBytes must be larger than kRegByteSize");
99 99
100 // Unused bits left in reg_. 100 // Unused bits left in reg_.
101 size_t bits_left_in_reg_; 101 size_t bits_left_in_reg_;
102 102
103 // Cache for appended bits. Bits are flushed to data_ with kRegByteSize 103 // Cache for appended bits. Bits are flushed to data_ with kRegByteSize
104 // granularity, i.e. when reg_ becomes full, or when an explicit FlushReg() 104 // granularity, i.e. when reg_ becomes full, or when an explicit FlushReg()
105 // is called. 105 // is called.
106 RegType reg_; 106 RegType reg_;
107 107
108 // Current capacity of data_, in bytes. 108 // Current capacity of data_, in bytes.
109 size_t capacity_; 109 size_t capacity_;
110 110
111 // Current byte offset in data_ (points to the start of unwritten bits). 111 // Current byte offset in data_ (points to the start of unwritten bits).
112 size_t pos_; 112 size_t pos_;
113 113
114 // Buffer for stream data. 114 // Buffer for stream data.
115 uint8* data_; 115 uint8_t* data_;
116 }; 116 };
117 117
118 } // namespace media 118 } // namespace media
119 119
120 #endif // MEDIA_FILTERS_H264_BITSTREAM_BUFFER_H_ 120 #endif // MEDIA_FILTERS_H264_BITSTREAM_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698