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

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

Issue 10780026: Add HE AAC support to ISO BMFF. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove aac.h. Created 8 years, 5 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 | « media/base/bit_reader.h ('k') | media/base/bit_reader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/base/bit_reader.h"
6
7 namespace media {
8
9 BitReader::BitReader(const uint8* data, off_t size)
10 : data_(data), bytes_left_(size), num_remaining_bits_in_curr_byte_(0) {
11 DCHECK(data_ != NULL && bytes_left_ > 0);
12
13 UpdateCurrByte();
14 }
15
16 BitReader::~BitReader() {}
17
18 bool BitReader::ReadBitsInternal(int num_bits, uint64* out) {
19 DCHECK_LE(num_bits, 64);
20
21 *out = 0;
22
23 while (num_remaining_bits_in_curr_byte_ != 0 && num_bits != 0) {
24 int bits_to_take = std::min(num_remaining_bits_in_curr_byte_, num_bits);
25
26 *out <<= bits_to_take;
27 *out += curr_byte_ >> (num_remaining_bits_in_curr_byte_ - bits_to_take);
28 num_bits -= bits_to_take;
29 num_remaining_bits_in_curr_byte_ -= bits_to_take;
30 curr_byte_ &= (1 << num_remaining_bits_in_curr_byte_) - 1;
31
32 if (num_remaining_bits_in_curr_byte_ == 0)
33 UpdateCurrByte();
34 }
35
36 return num_bits == 0;
37 }
38
39 void BitReader::UpdateCurrByte() {
40 DCHECK_EQ(num_remaining_bits_in_curr_byte_, 0);
41
42 if (bytes_left_ == 0)
43 return;
44
45 // Load a new byte and advance pointers.
46 curr_byte_ = *data_;
47 ++data_;
48 --bytes_left_;
49 num_remaining_bits_in_curr_byte_ = 8;
50 }
51
52 } // namespace media
OLDNEW
« no previous file with comments | « media/base/bit_reader.h ('k') | media/base/bit_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698