Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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 #ifndef MEDIA_BASE_BIT_READER_CORE_H_ | |
| 6 #define MEDIA_BASE_BIT_READER_CORE_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "media/base/media_export.h" | |
| 11 | |
| 12 namespace media { | |
| 13 | |
| 14 class MEDIA_EXPORT BitReaderCore { | |
| 15 public: | |
| 16 class ByteStreamProvider { | |
| 17 public: | |
| 18 ByteStreamProvider(); | |
| 19 virtual ~ByteStreamProvider(); | |
| 20 | |
| 21 // Request n number of bytes where: | |
| 22 // - n should be equal to or greater than |min_n|, | |
| 23 // - n must be less than or equal to |max_n|. | |
| 24 // Return the actual number of bytes available in |*array|. | |
| 25 virtual int GetBytes(int min_n, int max_n, const uint8** array) = 0; | |
|
acolwell GONE FROM CHROMIUM
2013/12/28 01:54:42
nit: Add text about the expected lifetime of |*arr
damienv1
2013/12/28 02:26:17
Will do.
| |
| 26 | |
| 27 // Return the number of bytes left in the stream. | |
| 28 virtual int GetBytesLeft() const = 0; | |
| 29 }; | |
| 30 | |
| 31 explicit BitReaderCore(ByteStreamProvider* byte_stream_provider); | |
|
damienv1
2013/12/28 01:32:25
Add a comment to say the lifetime of the ByteStrea
damienv1
2013/12/28 02:26:17
Done.
| |
| 32 ~BitReaderCore(); | |
| 33 | |
| 34 // Read |num_bits| next bits from stream and return in |*out|, first bit | |
| 35 // from the stream starting at |num_bits| position in |*out|. | |
| 36 // |num_bits| cannot be larger than the bits the type can hold. | |
| 37 // Return false if the given number of bits cannot be read (not enough | |
| 38 // bits in the stream), true otherwise. When return false, the stream will | |
| 39 // enter a state where further ReadBits/SkipBits operations will always | |
| 40 // return false unless |num_bits| is 0. The type |T| has to be a primitive | |
| 41 // integer type. | |
| 42 // T can especially not be a boolean since it generates | |
| 43 // some optimization warnings during compilation on windows platforms, | |
| 44 // use ReadFlag instead. | |
| 45 template<typename T> bool ReadBits(int num_bits, T *out) { | |
|
acolwell GONE FROM CHROMIUM
2013/12/28 01:54:42
nit: s/T *out/T* out/
damienv1
2013/12/28 02:26:17
Will do.
| |
| 46 DCHECK_LE(num_bits, static_cast<int>(sizeof(T) * 8)); | |
| 47 uint64 temp; | |
| 48 bool ret = ReadBitsInternal(num_bits, &temp); | |
| 49 *out = static_cast<T>(temp); | |
| 50 return ret; | |
| 51 } | |
| 52 | |
| 53 // Read a boolean. | |
| 54 bool ReadFlag(bool* flag); | |
| 55 | |
| 56 // Read an unsigned exp-golomb value. | |
| 57 bool ReadUE(uint32* out); | |
|
acolwell GONE FROM CHROMIUM
2013/12/28 01:54:42
nit: s/ReadUE/ReadExpGolomb/ ?
damienv1
2013/12/28 02:26:17
That was my original naming but I noticed the curr
acolwell GONE FROM CHROMIUM
2014/01/06 22:44:06
That is why I suggested ExpGolumb over UE because
| |
| 58 | |
| 59 // Skip |num_bits| next bits from stream. Return false if the given number of | |
| 60 // bits cannot be skipped (not enough bits in the stream), true otherwise. | |
| 61 // When return false, the stream will enter a state where further ReadBits/ | |
| 62 // SkipBits operations will always return false unless |num_bits| is 0. | |
|
acolwell GONE FROM CHROMIUM
2013/12/28 01:54:42
nit: ReadFlag & ReadUE should be added or the comm
damienv1
2013/12/28 04:02:23
Done.
| |
| 63 bool SkipBits(int num_bits); | |
| 64 | |
| 65 // Returns the number of bits read so far. | |
| 66 int GetBitCount() const; | |
| 67 | |
| 68 // Returns the number of bits available. | |
| 69 int bits_available() const; | |
| 70 | |
| 71 // RBSP stop bit. | |
| 72 bool HasMoreRBSPData(); | |
|
acolwell GONE FROM CHROMIUM
2013/12/28 01:54:42
This H.264 concept should not be here. Please move
damienv1
2013/12/28 02:26:17
Agree, I actually already started to do that (usin
| |
| 73 | |
| 74 private: | |
| 75 typedef uint64 RegType; | |
| 76 typedef int64 SignedRegType; | |
| 77 | |
| 78 // Help function used by ReadBits to avoid inlining the bit reading logic. | |
| 79 bool ReadBitsInternal(int num_bits, uint64* out); | |
| 80 | |
| 81 // Refill bit registers to have at least |min_nbits| bits available. | |
| 82 // Return true if the mininimum bit count condition is met after the refill. | |
| 83 bool Refill(int min_nbits); | |
| 84 | |
| 85 // Refill the current bit register from the next bit register. | |
| 86 void RefillCurrentRegister(); | |
| 87 | |
| 88 ByteStreamProvider* const byte_stream_provider_; | |
| 89 | |
| 90 // Number of bits read so far. | |
| 91 int bit_count_; | |
| 92 | |
| 93 // Number of valid bits left in |reg|. | |
| 94 // Note: bits are consumed from MSB to LSB. | |
| 95 int nbits_; | |
| 96 RegType reg_; | |
| 97 | |
| 98 // Number of valid bits left in |reg_next_|. | |
| 99 // Note: bits are consumed from MSB to LSB. | |
| 100 int nbits_next_; | |
| 101 RegType reg_next_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(BitReaderCore); | |
| 104 }; | |
| 105 | |
| 106 } // namespace media | |
| 107 | |
| 108 #endif // MEDIA_BASE_BIT_READER_CORE_H_ | |
| OLD | NEW |