summaryrefslogtreecommitdiffstats
path: root/media/base/bit_reader.cc
blob: c0d30d66fdd5d0deca5f446b25bd7e812cfbbd46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/base/bit_reader.h"

namespace media {

BitReader::BitReader(const uint8* data, int size)
    : initial_size_(size),
      data_(data),
      bytes_left_(size),
      bit_reader_core_(this) {
  DCHECK(data != NULL);
  DCHECK_GE(size, 0);
}

BitReader::~BitReader() {}

int BitReader::GetBytes(int max_nbytes, const uint8** out) {
  DCHECK_GE(max_nbytes, 0);
  DCHECK(out);

  int nbytes = max_nbytes;
  if (nbytes > bytes_left_)
    nbytes = bytes_left_;

  *out = data_;
  data_ += nbytes;
  bytes_left_ -= nbytes;
  return nbytes;
}

}  // namespace media