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

Side by Side Diff: media/base/bit_reader.h

Issue 112343011: Split the bit reader functionalities from the byte stream provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit test for the removal of the emulation prevention byte. Created 6 years, 11 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
« no previous file with comments | « no previous file | media/base/bit_reader.cc » ('j') | media/base/bit_reader.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef MEDIA_BASE_BIT_READER_H_ 5 #ifndef MEDIA_BASE_BIT_READER_H_
6 #define MEDIA_BASE_BIT_READER_H_ 6 #define MEDIA_BASE_BIT_READER_H_
7 7
8 #include <sys/types.h> 8 #include <sys/types.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/logging.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "media/base/bit_reader_core.h"
12 #include "media/base/media_export.h" 13 #include "media/base/media_export.h"
13 14
14 namespace media { 15 namespace media {
15 16
16 // A class to read bit streams.
17 class MEDIA_EXPORT BitReader { 17 class MEDIA_EXPORT BitReader {
18 public: 18 public:
19 // Initialize the reader to start reading at |data|, |size| being size 19 // Initialize the reader to start reading at |data|, |size| being size
20 // of |data| in bytes. 20 // of |data| in bytes.
21 BitReader(const uint8* data, off_t size); 21 BitReader(const uint8* data, off_t size);
22 ~BitReader(); 22 ~BitReader();
23 23
24 // Read |num_bits| next bits from stream and return in |*out|, first bit
25 // from the stream starting at |num_bits| position in |*out|.
26 // |num_bits| cannot be larger than the bits the type can hold.
27 // Return false if the given number of bits cannot be read (not enough
28 // bits in the stream), true otherwise. When return false, the stream will
29 // enter a state where further ReadBits/SkipBits operations will always
30 // return false unless |num_bits| is 0. The type |T| has to be a primitive
31 // integer type.
32 template<typename T> bool ReadBits(int num_bits, T *out) { 24 template<typename T> bool ReadBits(int num_bits, T *out) {
33 DCHECK_LE(num_bits, static_cast<int>(sizeof(T) * 8)); 25 return bit_reader_core_.ReadBits(num_bits, out);
34 uint64 temp;
35 bool ret = ReadBitsInternal(num_bits, &temp);
36 *out = static_cast<T>(temp);
37 return ret;
38 } 26 }
39 27
40 // Skip |num_bits| next bits from stream. Return false if the given number of 28 bool ReadFlag(bool* flag) {
acolwell GONE FROM CHROMIUM 2013/12/28 01:54:42 Why is this being added? It doesn't appear to be u
damienv1 2013/12/28 02:26:17 If we don't expose ReadFlag, all the parsers will
acolwell GONE FROM CHROMIUM 2014/01/06 22:44:06 I understand. I'd prefer you add it in a follow-up
41 // bits cannot be skipped (not enough bits in the stream), true otherwise. 29 return bit_reader_core_.ReadFlag(flag);
42 // When return false, the stream will enter a state where further ReadBits/ 30 }
43 // SkipBits operations will always return false unless |num_bits| is 0. 31
44 bool SkipBits(int num_bits); 32 bool SkipBits(int num_bits) {
33 return bit_reader_core_.SkipBits(num_bits);
34 }
45 35
46 // Returns the number of bits available for reading. 36 // Returns the number of bits available for reading.
47 int bits_available() const; 37 int bits_available() const {
38 return bit_reader_core_.bits_available();
39 }
40
41 int GetBitCount() {
acolwell GONE FROM CHROMIUM 2013/12/28 01:54:42 ditto
damienv1 2013/12/28 02:26:17 GetBitCount will remove the need of both: - NumEmu
acolwell GONE FROM CHROMIUM 2014/01/06 22:44:06 Ok, but I'd prefer you defer the addition of the m
42 return bit_reader_core_.GetBitCount();
43 }
48 44
49 private: 45 private:
50 // Help function used by ReadBits to avoid inlining the bit reading logic. 46 scoped_ptr<BitReaderCore::ByteStreamProvider> byte_stream_provider_;
51 bool ReadBitsInternal(int num_bits, uint64* out);
52 47
53 // Advance to the next byte, loading it into curr_byte_. 48 BitReaderCore bit_reader_core_;
54 // If the num_remaining_bits_in_curr_byte_ is 0 after this function returns,
55 // the stream has reached the end.
56 void UpdateCurrByte();
57 49
58 // Pointer to the next unread (not in curr_byte_) byte in the stream.
59 const uint8* data_;
60
61 // Bytes left in the stream (without the curr_byte_).
62 off_t bytes_left_;
63
64 // Contents of the current byte; first unread bit starting at position
65 // 8 - num_remaining_bits_in_curr_byte_ from MSB.
66 uint8 curr_byte_;
67
68 // Number of bits remaining in curr_byte_
69 int num_remaining_bits_in_curr_byte_;
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(BitReader); 50 DISALLOW_COPY_AND_ASSIGN(BitReader);
73 }; 51 };
74 52
75 } // namespace media 53 } // namespace media
76 54
77 #endif // MEDIA_BASE_BIT_READER_H_ 55 #endif // MEDIA_BASE_BIT_READER_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/bit_reader.cc » ('j') | media/base/bit_reader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698