Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / dom / media / BitWriter.h
blob6abf7bcde35c617459215f4dba9f3015ac0c7209
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef BIT_WRITER_H_
6 #define BIT_WRITER_H_
8 #include "mozilla/RefPtr.h"
10 namespace mozilla {
12 class MediaByteBuffer;
14 class BitWriter {
15 public:
16 explicit BitWriter(MediaByteBuffer* aBuffer);
17 virtual ~BitWriter();
18 void WriteBits(uint64_t aValue, size_t aBits);
19 void WriteBit(bool aValue) { WriteBits(aValue, 1); }
20 void WriteU8(uint8_t aValue) { WriteBits(aValue, 8); }
21 void WriteU32(uint32_t aValue) { WriteBits(aValue, 32); }
22 void WriteU64(uint64_t aValue) { WriteBits(aValue, 64); }
24 // Write unsigned integer into Exp-Golomb-coded. 2^32-2 at most
25 void WriteUE(uint32_t aValue);
26 // Write unsigned integer Little Endian Base 128 coded.
27 void WriteULEB128(uint64_t aValue);
29 // Write RBSP trailing bits.
30 void CloseWithRbspTrailing();
32 // Advance position forward without modifying buffer, which is usually used
33 // along with the case when directly appending a byte array to the
34 // MediaByteBuffer for the efficiency, instead of writing bits one by one.
35 // So this can only be called when the bit index is zero.
36 void AdvanceBytes(uint32_t aByteOffset);
38 // Return the number of bits written so far;
39 size_t BitCount() const { return mPosition * 8 + mBitIndex; }
41 private:
42 RefPtr<MediaByteBuffer> mBuffer;
43 size_t mPosition = 0;
44 uint8_t mBitIndex = 0;
47 } // namespace mozilla
49 #endif // BIT_WRITER_H_